Brew services start php70 with unix domain socket – without sudo

homebrewSecurity

I have homebrew's php70 installed and successfully connecting to apache via a unix domain socket.

I had to use sudo to start php though: sudo brew services start php70.

If I don't do this, the socket is created under my regular user account name, rather than with owner _www, the latter being essential to allow apache to access the socket.

Should I be starting php70 as root like this, or is there a safer way?

I tried creating a group with my own user name and apache as members of it, with intention of creating the socket under that group, but gave up as not entirely sure on the right track.

Am I wasting my time trying to avoid use of sudo? Maybe the answer is just .. 'it depends'.. ?

Best Answer

The command (sudo) brew services start php70 (or better (sudo) brew services start homebrew/php/php70) copies a special plist to a distinctive folder and launches and starts it as a launch agent or daemon.

Without the sudo prefix it's copied to the $USER's LaunchAgents folder (~/Library/LaunchAgents/) and started with $USER rights.

With the sudo prefix, the plist is copied to /Library/LaunchDaemons and started with root rights. It will launch several processes (one parent root php70-fpm and several child _www php-fpm processes).

Only the latter will and can create a UNIX socket file with the owner _www.

This is the expected behavior.