1

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?

1 Answer 1

1

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

You must log in to answer this question.

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