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?
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
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?