This guide walks through the steps necessary to setup PHP on Leopard. The basic steps are installing several prerequisites then recompiling Apache and PHP from source. It could totally bork your system, I'm just writing it down so the next time I need to do this I can remember what I did. I wish I could give credit to all the places I stole bits from but I didn't do a good job of keeping notes early on.
To follow these instructions you need to be running as the root user using the default sh shell. If you've got the correct administrator permissions you can switch users using the sudo command and providing your password.
localhost:~% sudo su -
Password:
sh-3.2# Install MacPorts
Follow the directions to install Mac Ports.
Then use port to grab a copy of wget and the GD dependency, jpeg, as well as freetype and t1lib for rendering fonts. You'll probably be in for a half our wait while a bunch of dependencies installed if this is the first time you've installed anything with port:
sh-3.2# /opt/local/bin/port install wget +ssl freetype t1lib jpeg
---> Fetching expat
---> Attempting to fetch expat-2.0.1.tar.gz from http://downloads.sourceforge.net/expat
[...]
---> Fetching jpeg
---> Verifying checksum(s) for jpeg
---> Extracting jpeg
---> Applying patches to jpeg
---> Configuring jpeg
---> Building jpeg with target all
---> Staging jpeg into destroot
---> Installing jpeg 6b_2
---> Activating jpeg 6b_2
---> Cleaning jpegRecompile Apache
Rather than just installing Apache from MacPorts I want to rebuild in the native OS X locations so I can use the built-in support. I tried to skip over this step but after wasting a bunch of time finally realized it was important. Grab the latest version of Apache 2.2 and extract it:
sh-3.2# bunzip2 httpd-2.2.11.tar.bz2
sh-3.2# tar xf httpd-2.2.11.tar
-- OR --
sh-3.2# tar xvfz httpd-2.2.11.tar.gzCompile it:
sh-3.2# cd httpd-2.2.11
sh-3.2# ./configure --enable-layout=Darwin --enable-mods-shared=all
[...]
sh-3.2# make installInstall MySQL
Download and install the official MySQL package for OS X.
Recompile PHP
Download the latest PHP source:
sh-3.2# cd /tmp
sh-3.2# wget http://us.php.net/get/php-5.2.8.tar.bz2/from/this/mirror
--2008-12-15 18:24:23-- http://us.php.net/get/php-5.2.8.tar.bz2/from/this/mirror
Resolving us.php.net... 208.69.120.36
Connecting to us.php.net|208.69.120.36|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://us.php.net/distributions/php-5.2.8.tar.bz2 [following]
--2008-12-15 18:24:28-- http://us.php.net/distributions/php-5.2.8.tar.bz2
Connecting to us.php.net|208.69.120.36|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9827180 (9.4M) [application/octet-stream]
Saving to: `php-5.2.8.tar.bz2'
100%[======================================>] 9,827,180 466K/s in 20s
2008-12-15 18:24:49 (474 KB/s) - `php-5.2.8.tar.bz2' saved [9827180/9827180]Extract it:
sh-3.2# bunzip2 php-5.2.8.tar.bz2
sh-3.2# tar xf php-5.2.8.tarCompile it:
sh-3.2# cd php-5.2.8
sh-3.2# MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" \
CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" \
CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" \
LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load"
sh-3.2# ./configure \
--prefix=/usr \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--with-apxs2=/usr/sbin/apxs \
--with-config-file-path=/etc \
--sysconfdir=/private/etc \
--enable-cli \
--with-curl=/opt/local \
--enable-ftp \
--enable-mbstring \
--enable-mbregex \
--enable-sockets \
--with-ldap=/usr \
--with-kerberos=/usr \
--with-mime-magic=/etc/apache2/magic \
--with-zlib-dir=/usr \
--with-xmlrpc \
--with-xsl=/usr \
--with-iconv=shared,/opt/local \
--with-openssl=shared,/opt/local \
--with-gd \
--with-png-dir=/usr/X11R6 \
--with-xpm-dir=/usr/X11R6 \
--with-jpeg-dir=/opt/local \
--enable-exif \
--with-freetype-dir=/opt/local \
--with-t1lib=/opt/local \
--enable-pdo \
--with-pdo-mysql \
--with-mysql-sock=/var/mysql \
--with-mysqli=/usr/bin/mysql_config \
--with-mysql=/usr/local/mysql \
--with-iodbc=/usr \
--with-curl \
--with-config-file-path=/etc \
--sysconfdir=/private/etc
[...]
Thank you for using PHP.
sh-3.2# make installFor what ever reason PHP gets built as php.dSYM so we'll just leave it there and symlink to it so future compiles will work correctly:
sh-3.2# if ( test -e /usr/bin/php && ! test -h /usr/bin/php) ; then mv /usr/bin/php /usr/bin/php.old; fi
sh-3.2# ln -s /usr/bin/php.dSYM /usr/bin/phpTest that PHP has GD installed:
sh-3.2# php -m |grep gd
gdIf you don't already have a php.ini file you'll need to create one by copying the default:
sh-3.2# if ( ! test -e /etc/php.ini ) ; then echo cp /etc/php.ini.default /etc/php.ini; fiEdit the php.ini so PHP can find the MySQL socket. Find the line with the mysqli.default_socket setting and change it to:
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sockRestart Apache:
sh-3.2# apachectl restartClean up
Once you've got everything working correctly you can remove the source code:
sh-3.2# rm -r /tmp/php-5.2.* /tmp/httpd-2.2.*This it actually pretty optional, when you reboot OS X cleans out the temp directory.
xdebug
i needed to install xdebug so
sudo pecl install xdebugdid the heaving lifting and adding:
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"to the php.ini file got it going.