Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 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
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 whilesudo 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? – glarkou Dec 24 '11 at 9:02
Thanks for the update. I would like to ask if its risky to add www-data to sudoers? – glarkou 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

Your Answer


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.