carl moonan | the dude abides

How to build & install PHP 5.2.2 on Mac OS X 10.4.9 intel

Working as of 2007/05/23 … if you are reading this & this date is very old then these instructions may not work as they do now.

To build PHP is pretty strait forward but like installing Subversion there is a dependency on a library called PEAR. Also PHP has a module that runs inside of apache and in this instance linked to MySQL. You can find instructions here to build and install Apache 2.2.4 and here for MySQL 5.0.41. You can attempt to install PHP without PEAR; if the .configure step fails just install PEAR as described below and redo PHP install.

Source code (http://www.php.net/downloads.php):
http://uk3.php.net/distributions/php-5.2.2.tar.gz

Install location on machine:

/usr/local/PHP/5.2.2/

Steps:
ensure go-pear.php has been run

curl http://go-pear.org > go-pear.php
sudo php go-pear.php

This will start an installation process. You can press enter to accept the defaults. You should see a menu after pressing enter twice. At the menu choose 1 to modify the Installation prefix to:

/usr/local/PHP/5.2.2

Once Pear is on the machine you are able to build PHP.

Steps:
download source code

curl http://uk3.php.net/distributions/php-5.2.2.tar.gz > php-5.2.2.tar.gz

unzip

tar -zxf php-5.2.2.tar.gz
cd php-5.2.2

configure

./configure --prefix=/usr/local/PHP/5.2.2 \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc \
--with-zlib \
--with-xml \
--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 \
--with-apxs2=/usr/local/Apache/2.2.4/bin/apxs

make

make

make test (please look for any glaring errors here)

make test

install

sudo make install



PHP should be built and installed to /usr/local/PHP/5.2.2/ and the apache module installed to /usr/local/apache/2.2.4/modules/libphp5.so we can now proceed to configure and test it. To make PHP available through apache we must update /usr/local/apache/2.2.4/conf/httpd.conf

At end of the LoadModule list add these lines

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

test by creating a .php file called test.php that is visible to the web server and ensure it contains this code:

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo( yields identical results.
phpinfo(INFO_MODULES);



Here is a build an installation script for the process described. Copy & paste it into a file. Make the file executable with chmod +x myBuildScript.sh

#!/bin/bash

curl http://go-pear.org > go-pear.php
sudo php go-pear.php

curl http://uk3.php.net/distributions/php-5.2.2.tar.gz > php-5.2.2.tar.gz
tar -zxf php-5.2.2.tar.gz
cd php-5.2.2
./configure --prefix=/usr/local/PHP/5.2.2 --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc --with-zlib --with-xml --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 --with-apxs2=/usr/local/Apache/2.2.4/bin/apxs

make
make test
sudo make install

2 Comments, Comment or Ping

  1. Jeff

    Thanks for the easy directions. I’m playing around on an old powerbook and am hoping these instructions would work also on a PPC machine…..??? Any resources or advice?

  2. Hello Jeff, i actually used these instructions to setup a mac mini power pc G4. they worked for most things till i got to PHP. Sadly the machine was a Panther install so the compile failed on lib XML i think. it was a little tough to get it working… i will revisit the problem if i upgrade to 10.4.9 and Tiger…

    I can suggest three things

  3. 1) try the above instructions if you are on Tiger they should work & let me know if they fail (sorry :o( if they fail!)
  4. 2) Mac Ports - http://www.macports.org
  5. 3) MAMP - http://www.living-e.de/en/products/webEdition/index.php
  6. I have used mac ports in one solution. This is because it is much closer to a compile and install.

    You must install mac port binary. it is a command line app. then u can use a command line like this to install php:

    sudo port -v install php5 +macosx +apache +mysql5 +pear

    this will pull down PHP, compile and link to apache, mysql5 and pear. i found this to work well in emergency situations where things just won’t work or compile. the instructions above should work but i found that my version of OSX being Panther led to some strange options being needed to compile PHP. it was failing when linking to the XML lib. i wish i could sort this. My plan is to check out the build process that Mac Ports is using and update the instructions e.g.

    pico /opt/local/var/db/dports/sources/rsync.rsync.darwinports.org_dpupdate_dports/www/php5/Portfile

    Please take note of how the program links to other programs, also note where it chooses to install. This is pretty important to have the correct paths etc. If you have chosen to install into another directory than the one i used then you should specify these.

Reply to “How to build & install PHP 5.2.2 on Mac OS X 10.4.9 intel”