To install PHP on Mac OS X 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 installation otherwise you will get compiler 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.
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=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2/bin/apxs
Before you continue, because of an error in 5.2.9 and 5.3.0 you ned to edit the Makefile generated by the configure fase. You need to add ‘-lresolv‘ at the end of the line which starts with ‘EXTRA_LIBS‘ like:
Do NOT replace the complete line, only add the last bit, as your configuration might be different.
To compile and install:
sudo make install
If the install fails because of a PEAR error like:
[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:
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‘.
Next step: Installing the Mailserver



1:39 am
Didn’t work for me. Trying to install php-5.2.10. Seeing the following errors:
checking host system type… config.sub: missing argument
Try `config.sub –help’ for more information.
configure: error: Cannot find OpenSSL’s libraries
-bash: –with-pdo-mysql=/usr/local/mysql: No such file or directory
Please help. Thanks, Timothy
4:17 am
The line:
–with-config-file-path=/etc/php.ini \
should instead be:
–with-config-file-path=/etc \
10:38 pm
Thanks *so* much for this guide– I had to go back to v.5.2.9, for which this also worked.
The only thing I had to tweak was the location of apxs– I changed:
–with-apxs2=/usr/local/apache2/bin/apxs
to
–with-apxs2=/usr/sbin/apxs
Everything else fell right into place. Thanks again.
1:17 pm
Thank you Richard for the great support. PHP 5.2.11 solved my problem with RouncubeMail after the upgrade of Snow Leopard.
Details: http://tinyurl.com/yasmdrr
8:10 am
I am maintaining PHP 5.2 build scripts as part of the Homebrew system which is optimised for snow leopard. At the moment it builds 64bit binaries using the LLVM compiler and works quite well.
It is trivial to edit the script and pick a particular version of 5.2 if 5.2.11 isn’t to your liking.
Full tutorial on my blog at http://boztek.net/blog/2009/10/07/install-lamp-stack-source-mac-os-x-106-snow-leopard-using-homebrew
8:35 am
Boris, thanks for the info. What is the difference in homebrew compared to Macports or fink which do the same in my opinion.
5:17 pm
Richard: It is similar but Homebrew doesn’t have any complicated package management and has the main philosophy of duplicating as little as possible – e.g. if software needs apache then use the built in apache, if it needs SSL, use the built in openssl, etc.
Macports tends to build duplicates of things.
Homebrew installs everything into /usr/local which by convention doesn’t require sudo to install software to.
The simplicity of the system means that if you need to update / alter the build yourself it’s much easier to do so then with something like Macports, it’s sort of in between building manually and having a completely managed but less flexible package system.
Homebrew also focuses on small fast optimised binaries.
11:27 pm
Hi Richard,
With 5.3.1 the configure script does produce a Makefile with this line:
EXTRA_LIBS = -lresolv -lmysqlclient -lssl -lcrypto -lz -lssl -lcrypto -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lmysqlclient -lz -lm -lmysqlclient -lz -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm
So it seems that adding the -lresolv is no longer necessary.