Installing Apache2 and PHP5 on Mac OS X Snow Leopard

I recently migrated to Mac and I have to say I’m really happy so far. I’m running Mac OS X Snow Leopard. My development environment is as follows:

  • Apache 2
  • PHP 5.3
  • PDO MySQL
  • Apc
  • Memcache
  • Xdebug
  • Imagick

I used to work with XAMPP under Windows XP. When I migrated to Mac I was first using MAMP as Snow Leopard just went out and I ran into multiple problems trying to compile PHP with the necessary extensions. I just found out that it’s not a problem anymore with the latest installations of XCode and MacPorts. Here’s how to install your dev machine…

Pre-requisites:

You will need to install Apple’s XCode (http://developer.apple.com/technology/xcode.html) and the latest version of MacPorts (http://www.macports.org/install.php). XCode provides the standards compiling tools while MacPorts is a very Debian like open-source software package manager.

Installation:

> sudo port install apache2

Then modify Apache’s configuration file to your needs. It is located under /opt/local/apache2/conf/httpd.conf.

> sudo port install php5 +apache2 +mysql5 +pear

This will take a little while as port retrieves, compiles and install PHP with MySQL5 and PEAR support. It will also build PHP as a Apache2 module. Notice the message at the end of installation asking you to perform the following to activate PHP as an Apache module:

> cd /opt/local/apache2/modules
> /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

Just add the following to the httpd.conf file:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Almost done but I need my favourite extensions:

sudo pecl install apc-beta
sudo port install php5-mbstring
sudo port install php5-curl
sudo port install php5-iconv
sudo port install php5-xdebug
sudo port install php5-mysql

Leave a Reply

Your email address will not be published. Required fields are marked *