So I want to execute the following command in my php script:
exec("/path/to/command");
Because it is the www-data user who runs php scripts, i currently can not run this command. I have read something about suexec being able to run a command as if it was a different user. I find it rather difficult to understand how this works.
I have already installed suexec and edited the /etc/apache2/suexec/www-data file and added:
/home/user_to_run_command/script.php
I have also edited /etc/apache2/sites-enabled/000-default and added:
SuexecUserGroup user_to_run_command user_to_run_command
Am I missing anything?
suEXEC will work only when PHP is executed in CGI mode but not if PHP is running as an apache2 module. I guess you are running it as a module.
An alternative might be to transfer the ownership to the desired user and then set the
suidbit:Now when executing
your.programit has permissions as if it where executed by it's owner. Follow the wiki article that I've linked for more information.Side note: This will work with binaries only (not with shell scripts as they where executed by the shell binary which has no suid bit set)