MacOS – Run Node commands for _www user

apachemacmacos

I've installed NodeJS for all users on my Mac and when I do a whoami in the terminal it says 'cameron' and I can access node, npm, and grunt globally.

However when I try and run these from PHP e.g. exec('npm install'); I can't run them because they don't exist! Doing a whoami in the PHP reveals that I'm running the website as _www which isn't an actual user on the Mac…

So basically how can I install Node for _www? So I can run these commands from PHP.

Best Answer

This fixes it (after changing apache to run as the user who has node or by giving access to _www).

putenv('PATH=' . getenv('PATH') . ':/usr/local/bin');