Set Environment Variables and Apache Server variables in Mavericks, Mountain Lion OSX 10.8 10.9 in Apache & PHP

I forget this regularly, so now I blog it so that I can find it again....


I have tried bash profiles, plist files, and the one that seems to work all the time is launchd configuration, that runs every time something runs?


1. To set environment variables run:


sudo vi /etc/launchd.conf


Enter your administrator password, then add in your environment variable like the following


setenv JAVA_HOME /Library/Java/Home


Save the file and if you run php_info you should see that an environment variable is set.


You can either restart your machine or run the following to get the environment variables set for everything (you will also need to restart application, apache and or terminal for it to be set)


grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl


If you instead need a server variable set then


2. To set server variables you need to edit your vhosts file, if you do not know what this is and want to set up a virtual host then have a look at this: Virtual Hosts setup


Edit your vhosts file:


sudo vi /path_to_your_vhosts_file/vhosts


Enter your administrator password, then add in your server variable like the following


SetEnv <servervariablename> "<servervariablevalue>"


That is it.

Comments