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
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.
1:43 am
[...] Download and build PHP in 64 bit mode. [...]
4:25 am
Hi richard, I am trying to install php 5.3.2 but I am getting an error in the ./configure part, the following are the last lines of the ./configure output:
checking for MSSQL support via FreeTDS… no
checking for MySQL support… yes
checking for specified location of the MySQL UNIX socket… no
checking for mysql_close in -lmysqlclient… no
checking for mysql_error in -lmysqlclient… no
configure: error: mysql configure failed. Please check config.log for more information.
So I am stuck in this part,
Thanks
7:54 am
@Nicolas, did you install MySQL as instructed?
http://diymacserver.com/installing-php/compiling-php-in-64-bits-mode-on-snow-leopard/
9:18 am
I have resolved the problem reinstalling the dmg and compilling, but now the ./configure says:
configure: WARNING: unrecognized options: –with-config-file-path, –with-zlib, –without-iconv, –enable-exif, –enable-ftp, –enable-mbstring, –enable-mbregex, –enable-sockets, –with-mysql, –with-pdo-mysql, –with-mysqli, –with-apxs2
usong php 5.3.2
9:49 am
Correction, the error generated by make is:
Generating phar.phar
dyld: Library not loaded: libmysqlclient.16.dylib
Referenced from: /Users/macbook/Downloads/php-5.3.2/sapi/cli/php
Reason: image not found
make: *** [ext/phar/phar.phar] Trace/BPT trap
10:18 am
@Nicolas, just tried it myself again and there should not be any error if you’ve installed everything as documented. I think you might have made a mistake in the mysql installation or did not clean up your previous PHP attempt. If you try to compile PHP again please run “make clean” before you run ./configure again.
The unrecognized options is an error on your behalf. You did something wring there as this should not happen. Please make sure you copy the command lines as shown.
9:13 am
I used the same configuration as you, with no editing, and PHP 5.3.3 configured correctly. When I tried make, it ended with this error:
In file included from /Users/server/src/php-5.3.3/ext/mysqli/php_mysqli_structs.h:57,
from /Users/server/src/php-5.3.3/ext/mysqli/mysqli.c:33:
/usr/local/mysql/include/mysql/my_global.h:1008: error: duplicate ‘unsigned’
/usr/local/mysql/include/mysql/my_global.h:1008: warning: useless type name in empty declaration
make: *** [ext/mysqli/mysqli.lo] Error 1
And of course, make install failed with the same error. I installed MySQL per your specifications.
9:16 am
Please read the blog, it’s already noted and solved with a patch: http://diymacserver.com/2010/07/23/php-released-5-3-3-has-small-issue/
9:56 am
I don’t want to be a pain, but how exactly do you apply a patch?
10:28 am
On the commandline:
patch [originalfile] [patchfile]
11:41 am
Also, my httpd.conf file doesn’t have the following lines:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Should I add them? The LoadModule line is in the configuration file.
The only AddType line in my config are:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
1:58 pm
Yes, please add them.