I would like to be able to run PHP commands, in system-function exec or whatever, but with a different user then www-data. OS: Ubuntu Server 10.10 Web Server: Apache2

I've searched for answers a couple of hours now, but it's a dead end. Most people says it's impossible and others don't know. I would like to run commands with a different user in PHP. This is kind of what I want: User presses a button that starts a screen running CS Source server. The screen is run from myuser.

Hope you'll understand what I want here. Also I don't know what function to use (system, exec or other) so some tips here as well could be usefull.

Thanks in advance!

migrated from stackoverflow.com Mar 6 '12 at 3:33

This question came from our site for professional and enthusiast programmers.


With SuExec you could do it, even easier is suphp, which has a package in Debian, so I assume Ubuntu will have it too. this seems a proper introduction. Of course, you could also use simple sudo functionality if it's just one or 2 commands instead of the whole site needing a different user. Better asked at http://www.serverfault.com if you run into problems with that one though.

  • @siXor, always be vary of "impossible" when there are hundreds of shared hosting providers which offer exactly this sort of service. As Wrikken says, you can easily do this with suEXEC or suPHP. – TerryE Mar 3 '12 at 23:55
  • Thanks for the answer, but I can't get suPHP working. I get an "Internal Server Error" when connecting to my site. I followed the tutorial you gave me and some others, but I just can't get it working. tail -f /var/log/suphp/suphp.log just gives me: File "/var/www/mysite/index.php" is writeable by group. I've got chmod 777 on my files for now just to test if it was going to work. – siXor Mar 4 '12 at 15:16
  • 1
    The key is less rights, not more, for your own safety suphp wants this. 0644 or 0600 on files, 0755 or 0700 on dirs. – Wrikken Mar 4 '12 at 17:43
  • Didn't work with 0755. Then there was no errors at all either. What can I do? – siXor Mar 4 '12 at 23:17
  • @siXor: check /var/log/audit/audit.log or dmesg(1) for AppArmor DENIED messages. – sarnold Mar 5 '12 at 1:20

I've been looking for an answer for this for a long time now and I finally got one. The solution is apache module mpm-itk.

apt-get install apache2-mpm-itk

And then add what user and group to run the virtual host in your virtual host file:

AssignUserId web_test web


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.