One solution is using sudo(8)
:
exec('sudo -u myuser ls /');
You will, obviously, need to setup sudo(8)
to allow the user running your webserver to invoke it. Editing the sudoers file with visudo(8)
, you can use something like:
wwwuser ALL=/usr/bin/rhythmbox-client
To prevent Apache from being able to run other commands and only the rythymbox command.