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

  • PHP would be started by Apache as a module, by the "Apache" user. You don't need to start it manually. – Allan Sep 5 '17 at 11:19
  • I'm not using apache's mod_php here. – mwal Sep 5 '17 at 12:22
  • Then why use _www? PHP will run as whatever user invokes it? – Allan Sep 5 '17 at 12:24

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.

  • Thanks - I think it was the advice that the brew command itself should never be used with sudo which might have been scaring me off - while it is more usual and apparently necessary in a case like this to start some services as root. – mwal Sep 7 '17 at 5:17
  • 1
    @mwal The brew services ... command is an exception. brew isn't required to install the launch daemon - you can do it yourself. It's just more work: 1. sudo cp plist 2. check permissions of the plist (ls plist) 3. sudo launchctl load plist (to start the daemon). – klanomath Sep 7 '17 at 5:24
  • To learn more I looked in /usr/local/Homebrew/Library/Homebrew/cmd where I found .rb scripts for many of the brew commands, but not services... interesting... – mwal Sep 7 '17 at 5:50

You must log in to answer this question.

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