12 Nov 2007, 6:38pm
/dev/random
by chris

8 comments

Leopard Also Breaks PHP

Today I got back to work on an old open-source PHP project called Drop Bocks, a simple file upload utility. Imagine my surprise in discovering that what used to work flawlessly under OS X 10.4 dies an ugly death under OS X 10.5:

Fatal error: Call to undefined function imagecreatefromjpeg()

It seems that in addition to damaging any installation of MySQL and Apache the upgrade to 10.5 also over-wrote my PHP install with an inferior, no-GD included version, which is a big feckin’ problem Apple.

Some googling turned up the following simple (<- that's sarcasm) solution to fix Apple's installation fubar:

Okay, here is the complete instruction on how to do this. Michel L already posted a very good message on how to build PHP with GD enabled, so i just combine all the answers in one step-by-step guide.

1. Download the Apache2 source from http://httpd.apache.org/download.cgi (latest version is 2.2.6) and extract it.
2. Open Terminal and go to that directory. If you extract sources into your Downloads folder, type “cd ~/Downloads/httpd-2.6.6″ and hit return
3. Type “./configure –enable-layout=Darwin –enable-mods-shared=all” and hit return
4. Wait for the process to complete and then type “make” and return
5. Wait for the process to complete and then type “sudo make install” and return

Now you have Apache2 built and installed and it should run perfectly.

Then, follow the Michel L instructions. I will copy them here with several modifications:

Install libjpeg ***
Get latest Stable SRC:

http://www.ijg.org/files/

tar zxvf jpegsrc.v6b.tar.gz

cd jpeg-6b

cp /usr/share/libtool/config.sub .

cp /usr/share/libtool/config.guess .

[Update: WordPress fiddles with double-dashes so the compiler flags in the following statements are incorrect (ie: –sysconfdir=/etc should be preceded by two dashes, not one). In the comments Mark has posted a corrected version down in the comments that you should follow. I'd correct them in the article but they are in fact correct in the article content; it appears WordPress mucks with them elsewhere, alas. - Chris]

env CFLAGS=”-O -g -arch i386 -arch ppc” LDFLAGS=”-arch i386 -arch ppc” ./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –mandir=/usr/share/man –enable-shared –enable-static

make

sudo make install

sudo ranlib /usr/local/lib/libjpeg.a

Install libpng ***
Get latest Stable SRC with config script

http://www.libpng.org/pub/png/libpng.html

tar jxvf libpng-1.2.22.tar.bz2

cd libpng-1.2.22

env CFLAGS=”-O -g -arch i386 -arch ppc” LDFLAGS=”-arch i386 -arch ppc” ./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –mandir=/usr/share/man –disable-dependency-tracking

make

sudo make install

sudo ranlib /usr/local/lib/libpng.a

The same procedure with PHP sources, and configure line should look like this:

./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –mandir=/usr/share/man –infodir=/usr/share/info –with-apxs2=/usr/sbin/apxs –with-curl –with-gd –enable-exif –enable-fastcgi –enable-zip –with-jpeg-dir=/usr/src/libjpeg –with-ldap=/usr –with-kerberos=/usr –with-zlib=/usr –enable-ftp –enable-sockets –with-iodbc=/usr –with-config-file-path=/etc –with-openssl –with-xmlrpc –with-xsl=/usr

If you have MySQL installed, add the following options to the PHP configure command (let’s assume you have your MySQL in /usr/local/mysql directory):
–with-mysql=/usr/local/mysql –with-mysql-sock=/var/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config

Then, run “make -j3″

And then, as usual, “sudo make install”

Note that PHP configure and build processes will take much time even on fast machine.

After all, go to “System Preferences > Sharing” and uncheck “Web Sharing” checkbox, then wait a bit and check it again. Now you should have your Apache+PHP up and running.

Screw that. From now on I’m using my Ubuntu machine for all PHP development until Apple finally starts shipping a decent development install or at the very least ships an OS that won’t fuck with mine.