-
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
-
-
Save srayhunter/5208619 to your computer and use it in GitHub Desktop.
@SubhajitSarkar are you trying to add an environment variable for Apache2 to use or for your terminal?
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:
<IfDefine SERVER_APP_HAS_DEFAULT_PORTS>
Listen 8080
</IfDefine>
<IfDefine !SERVER_APP_HAS_DEFAULT_PORTS>
Listen 80
</IfDefine>
I tried setting a SERVER_APP_HAS_DEFAULT_PORTS
true in env.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
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.
I'm getting the same issue.
Solution: For my case
source ~/.bash_profile
sudo apachectl stop
sudo apachectl start
And now it is working properly on Mojave.