Finding myself in need of a PostgreSQL server to test some patches for Drupal core, I've decided to do a follow up to my guide to getting PHP + GD + MySQL installed on OS X.
Fortunately for me John VanDyk wrote up Beginning with Drupal 6 and PostgreSQL on OS X 10.5 Leopard which covers the nitty gritty of getting PostgreSQL server installed. He doesn't address recompiling PHP so I'll pick up the story there.
Last Updated: June 1, 2009
First, a couple of notes on the formatting of this guide. The blocks of shell command typically include the shell prompt (sh-3.2#) when you're copying-and-pasting the command make sure you don't grab that part. Since this is long enough I've omitted large blocks of the compiler output and used [...] to indicated the omission.
Switch to the root account
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.
amorton@minivac:~% sudo su
Password:
sh-3.2# Install MacPorts
Since you have already followed John VanDyk's guide you'll have Mac Ports installed and only need to install a couple of extra packages.
Use port to grab a copy of wget and the GD dependency, jpeg, as well as freetype and t1lib for rendering fonts. You'll might see some other sub-dependencies installed during the process:
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:
sh-3.2# cd /tmp
sh-3.2# wget http://ftp.wayne.edu/apache/httpd/httpd-2.2.11.tar.bz2
--2008-12-15 18:04:55-- http://ftp.wayne.edu/apache/httpd/httpd-2.2.11.tar.bz2
Resolving ftp.wayne.edu... 141.217.1.55
Connecting to ftp.wayne.edu|141.217.1.55|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5230130 (5.0M) [application/x-tar]
Saving to: `httpd-2.2.11.tar.bz2'
100%[======================================>] 5,230,130 453K/s in 9.1s
2008-12-15 18:05:04 (561 KB/s) - `httpd-2.2.11.tar.bz2' saved [5230130/5230130]Extract it:
sh-3.2# bunzip2 httpd-2.2.11.tar.bz2
sh-3.2# tar xf httpd-2.2.11.tarCompile it:
sh-3.2# cd httpd-2.2.11
sh-3.2# ./configure --enable-layout=Darwin --enable-mods-shared=all
[...]
sh-3.2# make installRecompile PHP
Download the latest PHP source:
sh-3.2# cd /tmp
sh-3.2# wget http://us3.php.net/get/php-5.2.9.tar.bz2/from/this/mirror
--2009-05-19 12:40:42-- http://us3.php.net/get/php-5.2.9.tar.bz2/from/this/mirror
Resolving us3.php.net... 209.41.74.194
Connecting to us3.php.net|209.41.74.194|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://us3.php.net/distributions/php-5.2.9.tar.bz2 [following]
--2009-05-19 12:40:43-- http://us3.php.net/distributions/php-5.2.9.tar.bz2
Connecting to us3.php.net|209.41.74.194|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10203122 (9.7M) [application/octet-stream]
Saving to: `php-5.2.9.tar.bz2'
100%[======================================>] 10,203,122 308K/s in 34s
2009-05-19 12:41:16 (296 KB/s) - `php-5.2.9.tar.bz2' saved [10203122/10203122]Extract it:
sh-3.2# bunzip2 php-5.2.9.tar.bz2
sh-3.2# tar xf php-5.2.9.tarCompile it:
sh-3.2# cd php-5.2.9
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=/private/etc --sysconfdir=/private/etc --enable-cli --with-curl=/opt/local --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-ldap=/usr --with-ldap-sasl --with-kerberos=/usr --with-mime-magic=/etc/apache2/magic --with-zlib-dir=/usr --with-xmlrpc --with-xsl=/usr --without-iconv \
--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-pgsql=/opt/local/lib/postgresql83 --with-pdo-pgsql=/opt/local/lib/postgresql83
[...]
Thank you for using PHP.
sh-3.2# make installTest that PHP has the GD and PostgreSQL modules installed:
sh-3.2# php -m |grep "gd\|pgsql"
gd
pdo_pgsql
pgsqlIf 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 /private/etc/php.ini ) ; then echo cp /private/etc/php.ini.default /private/etc/php.ini; fiRestart 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.
Apache wont build
Hi,
I get the error:
sh-3.2# cd /tmp
sh-3.2# cd httpd-2.2.11
sh-3.2# make install
Making install in srclib
Making install in pcre
/opt/subversion/build-1/libtool --silent --mode=compile gcc -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/tmp/httpd-2.2.11/srclib/pcre -I. -I/tmp/httpd-2.2.11/os/unix -I/tmp/httpd-2.2.11/server/mpm/prefork -I/tmp/httpd-2.2.11/modules/http -I/tmp/httpd-2.2.11/modules/filters -I/tmp/httpd-2.2.11/modules/proxy -I/tmp/httpd-2.2.11/include -I/tmp/httpd-2.2.11/modules/generators -I/tmp/httpd-2.2.11/modules/mappers -I/tmp/httpd-2.2.11/modules/database -I/opt/subversion/include/apr-1 -I/opt/subversion/include -I/tmp/httpd-2.2.11/modules/proxy/../generators -I/tmp/httpd-2.2.11/modules/ssl -I/tmp/httpd-2.2.11/modules/dav/main -c maketables.c && touch maketables.lo
/bin/sh: /opt/subversion/build-1/libtool: No such file or directory
make[3]: *** [maketables.lo] Error 127
make[2]: *** [install-recursive] Error 1
make[1]: *** [install-recursive] Error 1
make: *** [install-recursive] Error 1
do you know how to get around this? Subversion 1.5 is installed.
//Paul Peelen
wrong libtool?
seems like it's finding the wrong libtool. you should probably dig around and check the ordering of your path. it's probably got the subversion build stuff ahead of the core osx bits.
starting/stopping web server environment
Hi,
Thank you for your article, I found it very useful. I would like to use my development web environment just only in specified times, I don't want it to consume resources when it is not necessary. With MySQL it could be achieved easily in this case, but the apache doesn't stop by 'apacechtl stop', some service is respawning it continuously.
Do you know any sophistecated way (eg. rc script) to achieve this?
Thank you in advance.
System Preferences
Yeah, launchd will restart it but it's easy enough to do. The big benefit of recompiling Apache in place is that we can use OS X's built in support for starting and stopping httpd. Go into the System Preferences > Sharing and uncheck the Web Sharing option.
What action to take after OSX updates
What happens to this PHP installation if an OSX update that comes with a newer version of PHP?
you've got to rebuild it
most of the system updates overwrite the php installation forcing you rebuild it. i end up cutting and pasting the build commands and it usually takes me a five or ten minutes. i view it as an opportunity to make sure i'm running the latest version of apache and php.