Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to play a sound file on my server using PHP. The PHP script is called by Apache and runs under the user 'nobody', which has by default no access to the speakers. So I created a new user soundoutput which is allowed do play sound and has read permissions for the sound files he should play.

If I'm logged in as root, I can play a sound file using echo password | sudo -Su soundoutput mpg321 '/path/to/sound.mp3'. The problem is, that it doesn't work when I'm executing this command using PHP's system_exec. I guess that user nobody isn't allowed to run sudo, but what can I do that he is allowed to do that?

Any help appreciated.

share|improve this question
Instead of putting nobody in the sudoers file (/etc/sudoers), which I consider a security risk, maybe you should make the script run as the soundoutput user. – Baarn Jul 20 '12 at 22:52
But how can I run this script as soundoutput? As far as I know, a PHP script is executed as the user who calls it. And for my apache server running as nobody, the script will also run as nobody. – frececroka Jul 21 '12 at 12:23
up vote 0 down vote accepted

Run Apache as httpd instead of nobody, then run:

# gpasswd -a httpd audio

That should grant the httpd user audio privileges.

Also, what is the goal? Have you thought of MPD? There are countless web clients you can use if you're just trying to play music.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .