Ubuntu – Run commands in PHP with different user

apache-2.2PHPterminalUbuntu

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!

Best Answer

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.

Related Topic