1

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.

2
  • 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, 2012 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.
    – Lorenz
    Jul 21, 2012 at 12:23

1 Answer 1

1

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.

You must log in to answer this question.

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