To install PHP on Mac OS X Snow Leopard there are, just as with Apache, several options one could use. I’ve chosen the most simple setup that will get most PHP based applications running that we need for the mailserver and such. Please remember that this is the 64 bit mode installation which requires a 64 bit MySQL and Apache installation otherwise you will get compiler and runtime errors.

You can start by downloading the latest source archive from www.php.net. Extract the source archive into a directory and use the Terminal to execute the following commands.

export MACOSX_DEPLOYMENT_TARGET=10.6 \
CFLAGS="-arch x86_64" \
CXXFLAGS="-arch x86_64"
./configure --prefix=/usr/local/php5 \
  --mandir=/usr/share/man \
  --infodir=/usr/share/info \
  --sysconfdir=/etc \
  --with-config-file-path=/etc \
  --with-zlib \
  --with-zlib-dir=/usr \
  --with-openssl \
  --without-iconv \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-mbregex \
  --enable-sockets \
  --with-mysql=mysqlnd \
  --with-pdo-mysql=mysqlnd \
  --with-mysqli=mysqlnd \
  --with-apxs2=/usr/local/apache2/bin/apxs

To compile and install:

make
sudo make install

After installation, please add the following lines to your ‘httpd.conf’ at the end.

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

Restart Apache and you’re ready to go.

As you might have seen from the ‘./configure‘ settings, your ‘php.ini‘ file will be located in ‘/etc‘.

If you need mcrypt or GD (graphics) look here.