Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save srayhunter/5208619 to your computer and use it in GitHub Desktop.
Save srayhunter/5208619 to your computer and use it in GitHub Desktop.
Configure Apache on Mac OSX with Environment Variables

Configure Apache Path Environment Variable on Mac OSX

Problem: Apache2/PHP did not find a program to execute on its configured path

Solution: Add a new path of /usr/local/bin to Apache2's path where the program was installed

  1. Edit the Apache2 plist file with whatever editor you like (example using vim):

     $ sudo vim /System/Library/LaunchDaemons/org.apache.httpd.plist
    
  2. 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>
    
  3. Restart Apache2

     $ sudo /usr/sbin/apachectl stop
     $ sudo /usr/sbin/apachectl start
    
@dzero1
Copy link

dzero1 commented Apr 30, 2021

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.

@hrodrig
Copy link

hrodrig commented Apr 27, 2022

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