i'm running apache on fedora and just can't seem to understand why i can't run any shell scripts in php using the exec function. It somehow just ignores the line calling the script.

previously this also happened in windows hosted apache that ran as a service, i had to run httpd.exe manually instead of service for php to be able to access external batch files.

so now..

let's say i have test.sh residing on /usr/....apache/myproject/tools/test.sh

i've already given it a chmod 777 and read and write access. But somehow it still doesn't work and shows no error.

I am totally new to linux world so I'm not too sure..do I need to set access from somewhere? I've read around forums saying php running on apache is actually running as 'apache' user, so how do i make 'apache' have access to shell scripts?

any help is very much appreciated!!

    Well if you wanted to give just the user apache access to the script (well, apache and root) then you could do:

    chown apache:apache /path/to/test.sh

    You also might want to look into use [man]shell_exec/man and also check to see if PHP is running in Safe Mode. If it is, then you need to put the shell script inside the safe-mode directory (whever that may be for your system).

      thanks,

      but i tried the command you gave me, and also tried changing the shell script's permission through fedora's interface, but both don't seem to work even though it's been set to apache.

      actually..i'm not too sure, how will i know what my apache is running as? when i checked on the root of apache's folder, it says it belongs to root. I tried changing all to root but it still doesn't seem to work.

      for simplicity sake i'm just testing whether it can call the shell script without accessing other folders :

      test.sh :

       #!/bin/bash
      
      echo Hello World

      when i ran 'sh /path/test.sh' from terminal, it will return me "Hello World". But if i ran it with exec("sh /path/test.sh", $output) or $output = shell_exec("sh /path/test.sh"), both $output won't have anything....that means..somehow, it can't access it yet.

      if apache's folder permission is 'root', does that mean apache is running as root? or is there any other places that i need to check to make php run scripts?

      edit :

      i just checked my error logs on apache, it says permission denied etc :

      "sh: /path/test.sh : permission denied"

      hi again..I just checked a few more things and found out that..

      1.my apache's home directory is at /var/www
      2. but apache was installed on /usr/local/apache2
      3. my project resides on /usr/local/apache2/htdocs/myproject

      when i put my test.sh into /var/www/ and chmod 777 to it, I'm able to execute the script from within php.

      does this mean that in order for me to access shell scripts from php, I MUST run the script from apache's home?

      another discovery!

      after granting test.sh as apache user, and i did chmod 777 again..but this time chmod to the full path /usr/local/apache2/htdocts/myproject/tools/test.sh i can get php to run it from /usr/local folder! funny...previously i tried granting access base on relative path but it won't work.

      but my final problem...is how am i able to give access to 'apache' to run soffice?

      if i call my test.sh from exec of php, and that my test.sh contains a call that needs to interact with open office (any application will do), i'll get access problem again.

      open office folder :
      /usr/lib/openoffice.org2.0/program/soffice

      the problem is, soffice is currently assigned to root, and i can't possible change it to 'apache' because someone else need to use it. How do i let apache use it? I can't find any interface in fedora that allows me to say..this file can be run by the following users..?

      edit :

      I installed open office 3, and been getting this error :
      [Java framework] Error in function createSettingsDocument (elements.cxx).javaldx failed!

        The User and Group apache run as is defined in httpd.conf with the User and Group options. By default they're set to be apache.

        I'm thinking that there is an issue with the php configuration. Maybe safe mode is on, or maybe there's some other restriction in effect. You could try turning the error_level up and set display_errors to on and see if you see anything.

        I just did a test-case where I put a script in /var/scripts named test.sh and in /var/www/html (my apache document root) I put a php script that just had this:

        <?php
        
        $output = `sh /var/scripts/test.sh`;
        
        echo $output;

        I got the expected results, and all I had to do was enable the executable flag for everyone (chmod +x test.sh) and make apache the owner and group of test.sh (chown apache:apache test.sh).

        As for your open office error, ask OpenOffice.Org users, as we don't support that here (mainly because we don't support any specific software; however, that is a JAVA application, not a PHP application).

          thanks bpat1434, i was able to run the shell scripts from php after giving it chmod 777 to absolute path.

          as for the open office problem, it went away when i try starting apache with "apachectl start" instead of "service httpd start". I don't know why.

          I have another problem that i'd like to put in another post..thanks alot!

            Write a Reply...