Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running exec as a different user

Tags:

php

exec

Is it possible to run exec() as a a different user (on my box it runs as www-data). I wish to execute a script that needs access to files that are not owned by www-data.

like image 622
mrwooster Avatar asked Jan 17 '11 09:01

mrwooster


1 Answers

If you have access to the server's configuration (assuming it's Apache), you might consider using suPHP. In a virtual host's configuration you can explicitly set the user and group for which a PHP script is executed:

<VirtualHost 192.168.1.1:80>
...
suPHP_UserGroup user group
...
</VirtualHost>

This setting is available for suPHP configurations built with the --with-setid-mode=paranoid option.

Another way to change the user ID would be posix_setuid() for which appropriate privileges are required. That would mean running your PHP scripts as root, which is a serios security issue.

like image 79
Linus Kleen Avatar answered Oct 21 '22 22:10

Linus Kleen