-
Edit the Apache2 plist file with whatever editor you like (example using vim):
$ sudo vim /System/Library/LaunchDaemons/org.apache.httpd.plist
-
Add the following to the the plist file:
<key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string> </dict>
-
Restart Apache2
$ sudo /usr/sbin/apachectl stop $ sudo /usr/sbin/apachectl start
Last active
April 27, 2022 12:56
-
-
Save srayhunter/5208619 to your computer and use it in GitHub Desktop.
Configure Apache on Mac OSX with Environment Variables
I had to run command "csrutil disable" in Terminal after rebooting and hitting CMD+R and then I was able to edit this file.
In catalina I had to mount the root to read/write using sudo mount -uw /
after disable csrutil.
I'm getting the same issue.
Solution: For my case (same than SubhajitSarkar)
I have put the environment variables in the ~/.profile (I'm using zsh on M1)
brew install httpd # run as non-root user on port 8080
...
nano ~/.profile
...
export MY_VAR="test"
...
source ~/.profile
apachectl stop
apachectl start
# php 8.x code
...
echo getenv('MY_VAR')
...
Output: test
And now it is working properly on Monterrey.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In Catalina this file is now on the new read-only system volume.
I'm not sure if it was there before but I see an empty
/private/etc/apache2/env.plist
which is maybe designed as a workaround?I have the Server app installed, which now has its own instance of apache running, the default apache has this but I'm not sure where to set this env variable:
I tried setting a
SERVER_APP_HAS_DEFAULT_PORTS
true inenv.plist
to no avail but it is possible I had the permissions wrong.In any case apache won't launch because of
httpd (pid 82785) already running
and need to stop the Server apps own apache:sudo launchctl unload -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.serviceproxy.plist