Technical article 126330

I am not able to execute a shell command in a PHP4 script under OpenServer 5.0.7 running native OpenServer 507 Apache

OpenServer 5.0.7

Written · Last revised

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
/tmp

I 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/htdocs

and a file test.txt is been created under /tmp

But instead, I only got this displayed on my browser:

hello world

No 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 ; then
Save the file, stop apache and then start it again:
# /usr/lib/apache/bin/apachectl stop
# /usr/lib/apache/bin/apachectl start

Now 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.

From the Xinuos technical article database, record 126330. Reproduced with permission. The original is at www.sco.com/ta/126330, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.