Unable to make shell_exec working

Discussion in 'Installation/Configuration' started by hubik.tomas, Mar 13, 2014.

  1. hubik.tomas

    hubik.tomas New Member

    Hello everybody,

    I installed ISPConfig on my Debian server recently. I followed this tutorial:
    http://www.howtoforge.com/perfect-server-debian-wheezy-apache2-bind-dovecot-ispconfig-3

    I am using stable Debian Wheezy with all packages up to date with ISPConfig 3.0.5.3. On one of my websites I would like to allow PHP shell_exec function for automatic deploy tool from local git repository. To be more specific, I would like to run git pull using a PHP script invoked through web browser.

    Unfortunately after some googling and reviewing logs I am not able to make this working. It looks like shell_exec is not working and not reporting any error anywhere. Checking /var/www/domain.tld/log/error.log and /var/log/apache2/error.log[. But there is nothing related to this.

    I also reviewed /etc/php5/apache2/php.ini for disabled shell_exec function but without any result. Also searching for safe_mode enabled but did not find it anywhere.

    In the settings of my website I have selected suEXEC and FastCGI as recommended in the manual. This may be the reason but I do not know how to make the shell_exec work with this settings.

    I also run phpinfo(); and nothing about enabled safe_mode or disabled shell_exec was mentioned.

    Thank you very much for any advice.

    Tomas
     
  2. LGM

    LGM New Member

    Check user and perms

    Hi Tomas,

    Its been a while since I've needed to configure php and exec, however, have you checked that the apache user, (which definitely should not be root) that maybe something like webadm or web-data, has all the permissions necessary to perform the command your trying to exec? ie. rx (read execute) permissions on any binaries or scripts you're trying to run, read access to any files or directories you need to read from and write access to the appropriate directories.

    That's assuming that you've setup php to run under the same account as apache, of course. (I'm slightly ashamed to admit that, I can't remember if its better to run php under a different user to apache or not).

    Also, check that the apache / php user has the correct shell configured in /etc/passwd and that's it not set to "/bin/false", and that you're either using absolute file references, ie /usr/bin/<binary> or that you have the $PATH variable correctly configured for the user (and remember that as the user never logs in, a number of the standard shell / bash configurations files are only loaded during login).

    If you have all that setup correctly then I'm out of ideas I'm afraid.

    Though you may want to configure php logging in php.ini.

    Cheers
    LGM
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    ISPConfig is not enabling safemode, and using php-fxgi with súexec is fine. Just check that the progam that yuwant to executed can be run by the user of that website. e.g. web1 for the first site, web2 for the second etc. you can see the username of the site user e.g. when you run "ls -la" in the web folder, the user that owns the web folder is the user that runs the php scripts.
     
  4. hubik.tomas

    hubik.tomas New Member

    Unable to make shell_exec working - solved

    Hello till, hi LGM,

    thank you very much for your tip. Even though I had everything set correctly, you helped me to solve the problem. I thought that my commands were not executed, but then I tried to execute them directly from the shell to check the permissions mentioned and realized that the command failed due to a typo. After correcting the typo everything works. Interesting is, that I did not see any error output when executing through shell_exec. I was also playing with some error outputs redirections so this may be the cause.

    Anyway thank you very much.

    Tomas
     

Share This Page