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

I moved from Ubuntu to CentOS and I now have a problem running adb from PHP.

I am trying to execute shell_exec("/path/to/adb devices");

and I get:

ADB server didn't ACK
failed to start daemon
error cannot connect to daemon
daemon not running. starting it now on port 5037

Of course adb is not able to start because it is already running and listening on port 5037 and If I try to run adb devices as root or as a regular user from the command line it returns all connected devices.

This configuration was previously working with Ubuntu.

What is the difference? Any suggestions?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I'm going to say it's a 90% chance it's SELinux related. You can confirm it by looking for entries in /var/log/audit/audit.log.

CentOS has SELinux enabled by default.

When you run adb from your PHP script, it is most likely running under httpd's security context, which doesn't permit outgoing network connections.

The quick fix is to allow httpd to make outgoing network connections:

setsebool -P httpd_can_network_connect on

Keep in mind that this will allow outgoing connections to anywhere.

The secure fix is to write a local policy confining adb and allowing it to connect to port 5037, access USB devices, etc., but this is a lot of work...

share|improve this answer
    
Thanks mate you saved us a lot of valuable time. –  salamis Oct 4 '12 at 20:41

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.