Problem
I have installed OpenServer 5.0.7 with Maintenance Pack 4
(MP4).I have written a simple PHP4 script "test.php" below:
--- cut here ---
<?php
echo("\nhello world\n - ");
echo getcwd(), "\n";
echo exec('touch /tmp/test.txt');
?>
--- cut here ---echo("\nhello world\n - ") --> Print hello world
echo getcwd(), "\n" ---> get the current PWD
echo exec('touch /tmp/test.txt') --> creat text.txt under
/tmpI placed it in the Apache root doc directory under /usr/lib/apache/htdocs.
When accessing this simple PHP4 script via http://<server>/test.php, I was expecting the following return on my web browser:
hello world - /usr/lib/apache/htdocsand a file test.txt is been created under /tmp
But instead, I only got this displayed on my browser:
hello worldNo current directory location output or any created text.txt file under /tmp. Looking into the /usr/lib/apache/logs/error_log file, I see the following error:
NoNe SuCh=: is not an identifier
NoNe SuCh=: is not an identifier Apache could not execute the two lines below in the PHP script
echo getcwd(), "\n"
echo exec('touch /tmp/test.txt')Is it at all possible to execute commands like such above in PHP4 via OpenServer 507 release of Apache?
Cause
It appears that it's an environment problem.
Solution
This problem has been reported to SCO Engineering.
To workaround the problem, edit the
/usr/lib/apache/bin/apachectl
file and add any text after the $HTTPD in the following
section:case $ARG in
start)
if [ $RUNNING -eq 1 ]; then
echo "$0 $ARG: httpd (pid $PID) already
running"
continue
fi
if $HTTPD ; then <---- Add the text in this line to like:
if $HTTPD hello world ; thenSave the file, stop apache and then start it again:
# /usr/lib/apache/bin/apachectl stop
# /usr/lib/apache/bin/apachectl startNow when accessing the test.php via web browser, I get all the three commands execute:
hello world - /usr/lib/apache/htdocs <-- output in the browser and a file test.txt is generated in /tmp.