READ THIS These instructions are old and no longer apply to most installs. If you're running Snow Leopard and you want to build PHP 5.3, you should check out my updated blog entry.
NOTE: this howto is now pretty outdated. I'll probably be reinstalling Leopard in the near future because Apple hates me so I'll update it when I rebuild.
Over the past many weeks, I've been tasked at well over 100% completing a not-so-secret project. If I've blown you off in email or on IRC, I'm sorry. I've been too busy to deal with much of anything, and I've let many things slide (as can be witnessed by this Friday night blog post). Do ping me again, if I missed you.
Anyway, one of the things that happened during development was an upgrade to Mac OS X 10.5 - Leopard. There are a bunch of things wrong with Leopard, but over all I'm pretty happy with it. I did, however, have a bit of a hard time getting my development environment up and running (I did a clean install). After the jump, I'll outline the steps that I took to get a functioning Apache, PHP, MySQL installed. Sure, you could use the leopard-bundled Apache and PHP, but if you're like me, you generally upgrade PHP (and use weird extensions) a lot more often than Apple will upgrade it.
Built on Rasmus' birthday. How appropriate (-:
First, a couple things should be noted: I'm still without local SSL support on Apache. I've been in touch with the maintainer of apache2 on macports (who, coincidentally, is probably familiar to many of you due to his past work on the PHP project: James Cox), but I still don't have a solution. See this bug report for info. The second thing is that my colleague/client/boss/friend (wow.. that sounds like a dangerous combination!) Marco helped me out quite a bit with the initial leopard-friendly incantations to make things build.
On with the compiling!
First things first: you'll need to download/install some packages. You'll need Xcode from the Leopard Install DVD, or from here. Xcode contains the compiler tools and a bunch of other stuff for Mac OS. Be forewarned: the download is bigger than 1GB!
Download and install MySQL from here. Yes, it says 10.4, but it works fine with Leopard (for me, anyway). Install it and the startup item that's in the DMG.
Then, download and install Macports this is the OS X port of the FreeBSD Ports system, and while I prefer pre-built packages like those offered in Fink (apt-get is nice), when I checked installing Fink on Leopard consisted of weird contortions involving a bootstrap from Tiger. No thanks. Install macports.
You'll also need a recent version of PHP. I have 5.2.5. Get it here.
Now that you have the necessary files, you'll need to fire up Terminal. The beauty of OS X is that when the GUI fails you, there's an underlying unix system that does what you command! (-:
MySQL installs strangely. Let's fix that. As root do this:
With MySQL taken care of, we'll move on to ports. Again, as root:
port selfupdate #makes sure ports is up to date port sync #syncs with the remote port index (like apt-get update)
Now, let's use ports to install the necessary packages. Again as root:
port install apache2 # install apache 2.2.x port install apache2 # yes, you need to do it twice, thanks to a bug that doesn't see awk the first time launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist #startup item (as instructed by the apache port output) cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf # copy the config file mv /usr/sbin/apachectl /usr/sbin/apachectl-leopard # move the bundled apachectl out of the regular path ln -s /opt/local/apache2/bin/apachectl /usr/local/bin/apachectl #and move the port-installed apache2 into the path
Congratulations. Apache is (almost) installed (-:
As root, you'll need to: edit
/opt/local/apache2/conf/httpd.conf and comment out this line:
LoadModule ssl_module modules/mod_ssl.so (see the bug mentioned above).
sudo apachectl start
Then point your browser at
localhost. You should get a page stating "It works!" Now, let's build PHP.
Before you do, you'll need to
port install some libraries
(depending on your configure line for PHP; mine's below). As root:
port install jpeg port install libpng port install freetype port install libmcrypt port install tidy #leopard comes with Tidy, but it's got a broken header file
Unpack the downloaded php tarball and
cd to the directory
where you extracted it. Here's my configure line:
'./configure' \ '--prefix=/Users/sean/php' \ '--with-apxs2=/opt/local/apache2/bin/apxs' \ '--with-xsl=/usr' \ '--with-tidy=/opt/local' \ '--enable-mbstring' \ '--with-gd' \ '--with-jpeg-dir=/opt/local' \ '--with-png-dir=/opt/local' \ '--with-zlib-dir' \ '--enable-sockets' \ '--enable-exif' \ '--with-mcrypt=/opt/local' \ '--enable-soap' \ '--with-mysql=/usr/local/mysql' \ '--with-pdo-mysql=/usr/local/mysql/bin/mysql_config' \ '--with-mysql-sock=/tmp/mysql.sock' \ '--with-freetype-dir=/opt/local' \ '--with-openssl=/opt/local' \ '--without-iconv' \ '--enable-cli'
sudo make install. You should now
have a functioning PHP. I moved the leopard-bundled PHP out of the way and
mine into its place with this (as root):
mv /usr/bin/php /usr/bin/php-leopard ln -s /Users/sean/php/bin/php /usr/bin/php
The only thing that remains is to tell Apache how to handle PHP files.
Add these lines to
LoadModule php5_module modules/libphp5.so # make install should have done this for you AddHandler application/x-httpd-php .php AddHandler application/x-httpd-php-source .phps
You may also want to tweak the default
DirectoryIndex to add
/opt/local/apache2/htdocs/info.php with the
<?php phpinfo(); ?>
sudo apachectl restart.
If all went well, you should see your new php's phpinfo output. If not... something went wrong (or I screwed up the instructions). Either way, post a comment, and I'll try to help.
Hope this helps you.. it would have saved me a few hours, if I had run into something similar.