1

I have a PHP script that run's the following command using exec()

/root/gsutil/gsutil <COMMAND>

In my error logs I receive the following:

sh: 1: /root/gsutil/gsutil: Permission denied

Does anyone know what I can do to allow my php script to run that command?

1
  • You cannot have it to run that program as it is (unless you are root?), and quite frankly you don't want to.
    – didierc
    Feb 14, 2015 at 18:18

1 Answer 1

4

Anything under /root is usually owned by the root user. PHP does usually not (and for security reasons should never) run under the root user. You should install the gsutil in a location where PHP has execute rights. For example, copy it to /var/www:

cp /root/gsutil/gsutil /var/www/gsutil

I think that under Ubuntu PHP usually runs as the www-data user (not 100% sure though), so you'll need to change ownership of the file to that user:

chown www-data.www-data /var/www/gsutil

Finally, make sure the file is executable for the owning user/group (www-data) by setting chmod 770:

chmod 770 /var/www/gsutil

Then set your PHP script to run /var/www/gsutil instead and all should run fine.

3
  • 2
    If the php script is launched by the Web server then it will run as www-data, otherwise it will be usual Unix rules (there's a cli install of Php available). Actually even when from apache, if it is in a user public_html directory, and the uuserdir mod is enabled, it will run as the user (but NOT root).
    – didierc
    Feb 14, 2015 at 18:13
  • Thanks for the help. This put everything into perspective. I ended up moving the gsutil like you said (but I moved it to /usr/bin/) and editing where it was in ~/.bashrc and changing export PATH=${PATH}:$HOME/gsutil to export PATH=${PATH}:/usr/bin/gsutil
    – bryan
    Feb 14, 2015 at 18:20
  • Somewhere where PHP has read rights, not execute rights, right?
    – user253751
    Feb 14, 2015 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .