Getting PHP + GD working on Leopard (aka recompiling everything)

Here's my writeup on how to recompile PHP for Leopard to get GD working so you can use use Drupal. The basic plan is recompile Apache and PHP from source. It may 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.

Install MacPorts

Follow the directions to install Mac Ports.

Then use port to grab a copy of wget and the GD dependency, jpeg. 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:

amorton@minivac:~% sudo su
Password:
sh-3.2# /opt/local/bin/port install wget jpeg
--->  Fetching expat
--->  Attempting to fetch expat-2.0.1.tar.gz from http://downloads.sourceforge.net/expat

[...]

--->  Staging wget into destroot
--->  Installing wget 1.11.4_0
--->  Activating wget 1.11.4_0
--->  Cleaning wget

--->  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 jpeg

Recompile 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://download.nextag.com/apache/httpd/httpd-2.2.9.tar.bz2
--2008-06-20 14:41:06--  http://download.nextag.com/apache/httpd/httpd-2.2.9.tar.bz2
Resolving download.nextag.com... 216.185.208.5
Connecting to download.nextag.com|216.185.208.5|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4943462 (4.7M) [application/x-bzip2]
Saving to: `httpd-2.2.9.tar.bz2'

100%[======================================>] 4,943,462   1.13M/s   in 4.3s   

2008-06-20 14:41:10 (1.09 MB/s) - `httpd-2.2.9.tar.bz2' saved [4943462/4943462]

Extract it:

sh-3.2# bunzip2 httpd-2.2.9.tar.bz2

sh-3.2# tar xf httpd-2.2.9.tar

Compile it:

sh-3.2# cd httpd-2.2.9

sh-3.2# ./configure --enable-layout=Darwin --enable-mods-shared=all

[...]

sh-3.2# make

[...]

sh-3.2# make install

Install MySQL

Use port to install MySQL:

sh-3.2# port install mysql5 +server
--->  Fetching mysql5
--->  Verifying checksum(s) for mysql5
--->  Extracting mysql5
--->  Configuring mysql5
--->  Building mysql5 with target all
--->  Staging mysql5 into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting mysql5 with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
###########################################################
--->  Installing mysql5 5.0.51_0+server
******************************************************
* In order to setup the database, you might want to run
* sudo -u mysql mysql_install_db5
* if this is a new install
******************************************************
--->  Activating mysql5 5.0.51_0+server
--->  Cleaning mysql5

You'll need to create the databases:

sh-3.2# /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
Installing MySQL system tables...
080618  0:14:33 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
OK
Filling help tables...
080618  0:14:34 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
OK

[...]

Let launchd know it should start MySQL at startup.

sh-3.2# launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

Create a symlink for the mysql5 executable so it can be invoked as mysql (the way that the mysql_secure_installation script expects it to be named):

sh-3.2# ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql

Secure the server and set a new admin password:

sh-3.2# /opt/local/lib/mysql5/bin/mysql_secure_installation

Create a configuration file:

sh-3.2# cp /opt/local/share/mysql5/mysql/my-large.cnf /etc/my.cnf

Finally create some symlinks so that PHP can find the insanely installed MySQL headers and libraries:

sh-3.2# ln -s /opt/local/lib/mysql5/mysql /opt/local/lib/mysql

sh-3.2# ln -s /opt/local/include/mysql5/mysql /opt/local/include/mysql

Recompile PHP

Download the latest PHP source:

sh-3.2# cd /tmp

sh-3.2# wget http://us3.php.net/get/php-5.2.6.tar.bz2/from/this/mirror
--13:11:09--  http://us3.php.net/get/php-5.2.6.tar.bz2/from/this/mirror
           => `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.6.tar.bz2 [following]
--13:11:09--  http://us3.php.net/distributions/php-5.2.6.tar.bz2
           => `php-5.2.6.tar.bz2'
Connecting to us3.php.net|209.41.74.194|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9,571,312 (9.1M) [application/octet-stream]

100%[====================================>] 9,571,312    134.55K/s    ETA 00:00

13:11:52 (218.56 KB/s) - `php-5.2.6.tar.bz2' saved [9571312/9571312]

Extract it:

sh-3.2# bunzip2 php-5.2.6.tar.bz2

sh-3.2# tar xf php-5.2.6.tar

Compile it:

sh-3.2# cd php-5.2.6

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-gd --with-png-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6 --enable-gd-native-ttf --with-jpeg-dir=/opt/local --enable-exif --with-mysqli=/opt/local/bin/mysql_config5 --enable-pdo --with-pdo-mysql=/opt/local/bin/mysql_config5 --with-mysql=/opt/local --without-iconv

[...]

Thank you for using PHP.

sh-3.2# make

[...]

Build complete.
Don't forget to run 'make test'.

sh-3.2# make install

For 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# mv /usr/bin/php /usr/bin/php.old

sh-3.2# ln -s /usr/bin/php.dSYM /usr/bin/php

Test that PHP has GD installed:

sh-3.2# php -m |grep gd
gd

Edit the php.ini so PHP can find the MySQL socket. If you don't already have a php.ini file you'll need to create one by copying the default:

sh-3.2# cp /etc/php.ini.default /etc/php.ini

Once you're editing the .ini file, find the line with the mysqli.default_socket setting and change it to:

mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock

Restart Apache:

sh-3.2# apachectl restart

Clean 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.*

apache does not compile

i was on my way to compile apache2 when (surprise!) some compilation errors came, starting form

awk -f /users/michael/temp/httpd-2.2.9/build/make_exports.awk `cat export_files` > exports.c
/opt/local/share/apr-1/build/libtool --silent --mode=compile /usr/bin/gcc-4.0 -DDARWIN

[skipped ...]

/../generators -I/users/michael/temp/httpd-2.2.9/modules/ssl -I/users/michael/temp/httpd-2.2.9/modules/dav/main -prefer-non-pic -static -c exports.c && touch exports.lo
exports.c:1287: error: redefinition of 'ap_hack_apr_allocator_create'
exports.c:152: error: previous definition of 'ap_hack_apr_allocator_create' was here
exports.c:1288: error: redefinition of 'ap_hack_apr_allocator_destroy'

[ a bunch more ...]

not sure

not sure why you'd be running into that. i keep updating these instructions each time i've re-run them on new machines and i've never seen that. please post a follow-up if you figure anything out.

What are the installation paths?

Hi, thanks for this guide. I had installed some of these with XAMPP. The reason I found your guide is that I need to build PHP and Apache with Postgresql support.

My questions:

1. Could you please add some info on (or email me, thanks) with the paths of these things that we have installed?

2. What is the command to build Postgresql into PHP?

Thanks!

postgresql

i've never setup pgsql on the mac so i can't offer much guidance other than using port to install it and then adding in some of the pgsql options when compiling php. lullabot seems to have a pretty good write up on it though: http://www.lullabot.com/articles/beginning-drupal-6-and-postgresql-os-x-...

Many thanks

This was invaluable for getting my 10.5 localhost set up for Drupal - many thanks.

Finally

Thanks drewish, I was having a hard time to make this work. Your post worked flawlessly.

Daniel.

build --with-mysql

Work great with this guide.. thank you..
I wonder if I want to build php with mysql module not with mysqli,
seem like compile need mysql header files...

I browse all site with no luck searching mysql header for leopard.
Any idea with this problem??

give it another try

I just updated the instructions to build --with-mysql. Basically you need to install mysql from MacPorts and then add some symlinks so that the configure script can find the lib and includes.

for you, a photo

hungry jack's

ads

User login