myfixlog.com Got a fix, how to, or an answer? Earn some money!

... Info Report ...
Views: 28
This fix has not been rated
Did this work for you?
Logger: jake
Date: January 23rd, 2013
| Share
... ...
Amixer doesn't work when executed in PHP

The Problem

I am building a web interface for my audio on Ubuntu Server 12.04.  I want to mute the mic from my browser, however, the command exec("amixer sset 'Mic',0 mute"); worked only intermittently.

Tags: php, exec, amixer, system, passthru

The Fix

Summary: The problem is that the user www-data had in ufficient permissions to run amixer.  To fix this you need to first determine the user that php uses:

echo exec('whoami');

Then I gave that user passwordless privelages to run one script under my account (jake):

sudo visudo

And insert this line, filling in your info:

www-data    ALL=(your username here - in my case jake) NOPASSWD: /home/jake/scripts/mute.sh

Then I put the command that I wanted to run (amixer sset 'Mic',0 mute) in the mute.sh bash file. And I executed the script in PHP as shown below:

exec("sudo -u jake /home/jake/Scripts/./mute.sh");

Now amixer mutes every time!


Additional Resources

There are no resources.

Comments

Add a Comment
There are no comments.
AboutContact