I noticed that a lot of people wanted to install and compile their own version of PHP but wanted to use the default apache installation that is available in Leopard. The compilation instructions differ a bit from my original instructions so I decided to write a separate instruction set for this.

I’ve chosen the most simple setup that will get most PHP based applications running that we need for the mailserver and such. 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.

./configure –prefix=/usr/local/php5 \
  –mandir=/usr/share/man \
  –infodir=/usr/share/info \
  –sysconfdir=/etc \
  –with-zlib \
  –with-zlib-dir=/usr \
  –with-openssl \
  –enable-exif \
  –enable-ftp \
  –enable-mbstring \
  –enable-mbregex \
  –enable-sockets \
  –with-mysql=/usr/local/mysql \
  –with-mysqli=/usr/local/mysql/bin/mysql_config \

sudo make install

If the install fails because of a PEAR error like:

[PEAR] Archive_Tar: commit failed
[PEAR] Console_Getopt: upgrade to a newer version (1.2 is not newer than 1.2)
warning: pear/PEAR dependency package “pear/Archive_Tar” installed version 1.1 is not the recommended version 1.3.1
[PEAR] PEAR: commit failed

You’ll need to upgrade the PEAR package on your machine. Save the script at http://pear.php.net/go-pear to your desktop as go-pear.php and execute ‘sudo php go-pear.php’. Just answer the questions when needed, most can be answered by just pressing the enter button. The most important one is to change the installation prefix from ‘/usr‘ to ‘/usr/local/php5‘ and that is it. Try to rerun the ‘sudo make install’ in the PHP source directory and it should work.

After installation, please check if the your ‘httpd.conf’ has been updated for the PHP extension and if the module is being loaded. Your ‘httpd.conf’ file should have the following lines:
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Restart Apache and your ready to go.

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