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

Here's my writeup on how to recompile PHP for Leopard to get GD working. 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.

Recompile Apache

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:

amorton@minivac:~% sudo su
Password:
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 MacPorts

Follow the directions to install Mac Ports.

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.darwinports.mysql5.plist

Secure the server and set a new admin password:

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

Put the socket where PHP is expecting it:

sh-3.2# ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock

Install GD prerequisites

Use port to install libjpeg:

sh-3.2# port install jpeg
--->  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 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-gd --with-png-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6 --enable-gd-native-ttf --with-jpeg-dir=/usr/local/lib --with-curl=/usr  --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-ldap=/usr --with-kerberos=/usr --with-mime-magic=/etc/apache2/magic --without-sqlite --with-mysqli=/opt/local/bin/mysql_config5 --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

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.5* /tmp/httpd-2.2.8*

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

for you, a photo

start of dabby's birtyday alleycat

ads

User login