Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to run adb from PHP using:

exec( 'adb devices', $output, $return_val );

but I get 126 error.

I think the problem is that php is running as 'www-data' user and does not have permissions to execute adb.

Any solutions?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This page shows that this error code means a permission problem or the program can not be executed.

If your program is executable (have x permission), you need to make sure it can be executed by www-data user.

If it requires super user privilege, you need to setup sudo without password for www-data to execute this command. You need to edit sudoers file using sudo visudo. Then, add a line like:

www-data ALL=NOPASSWD: /path/to/your/program

To run a command as different user, you can use the form:

sudo -u username command
share|improve this answer
    
The program that I am trying to run is adb for Android and I have allready added it to the Path= for the current user. When I run adb devices is working just fine while`sudo adb devices` it is not working as it cannot find adb. Can I just add www-data to execute files as the current user and not root? is that possible? or should I add adb to the environment variable for super users? –  salamis Dec 24 '11 at 9:02
    
Thanks for the update. I would like to ask if its risky to add www-data to sudoers? –  salamis Dec 24 '11 at 9:07
    
It depends on the privileges you are granting. If you are granting a specific the privilege to execute a single unrisky program, it should be fine. –  Khaled Dec 24 '11 at 9:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.