Mac – How to set which Apache / PHP 10.6 should run

apachemacports

All my problems stemmed from trying to get mcrypt for PHP installed. Last night I gave in and followed a tutorial of how to do a totally fresh apache2 and php5.3.3 install. I did this using MacPorts.

Sadly, that didn't enable mcrypt for me last night, although I was pretty pleased that I got 5.3.3 running. 🙂

The problem is that I have woken up this morning to find that my php version is back down to 5.3.1 which can only mean that OS X has reverted to my original Apache and PHP.

How to I tell OS X to use the software I installed via MacPorts?

(And then I will as a new question of how to enable mcrypt)

Best Answer

It's not so much your version of Apache/PHP have been reverted - it's just the wrong version is loaded.

If you have Mac OS X's Web Sharing enabled it will auto enable the version of Apache and PHP Apple provides using the LaunchDaemon org.apache.httpd.plist in /System/Library/LaunchDaemons (this will override MacPorts version). You'll want to disable this by either turning off Web Sharing in the Sharing Preference Pane or by running sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist.

When you installed Apache for MacPorts it installed a LaunchDaemon into /Library/LaunchDaemons which if enabled will start up the MacPorts version of Apache automatically. To enable it run sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist and you're off to the races.

If you're running apachectl to restart - make sure you've selected the right version. You may need to alter your $PATH to have /opt/local/apache2/bim before /usr/sbin

As for what version of PHP is being used; on the command line this will depend on your $PATH while for Apache it's entirely in your configuration of where the libphp5 module is. (/etc/apache2/ for the built in version, /opt/local/apache2/conf for the version MacPorts installed)