Install Apache and PHP on Leopard with MacPorts

If you have a Mac with Leopard installed, you should have Apache and PHP installed on it by default. If you try to modify your PHP installation however, this is where you run into problems. This was easy to do with Tiger, and I had written several articles on how to do this. Eventually, when I installed Leopard, my dev environment no longer worked.

I found a solution to this problem with MacPorts. The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system.

With MacPorts, it’s easy to install Apache and PHP into an environment you control. MacPorts makes it easy to add libraries to configure your installation however you want. It also makes it easy to update the software whenever you need to. I recommend using this to install your own dev environment on your Mac. Here is a good tutorial for installing Apache and PHP with MacPorts.

Note: the shortcut apache2ctl didn’t work for me because I am using .bash_profile on my machine instead of .profile which MacPorts installs. If you have this problem, you need to add a line of code to .bash_profile. Add the line below to .bash_profile and the shortcut apache2ctl should work.

alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'