Leopard Also Breaks PHP

   By chris on November 12th 2007 in /dev/random | 1,819 views

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.

8 Responses to “Leopard Also Breaks PHP”

  1. Peter responded on 22 Dec 2007 at 1:28 pm #

    Hi Cris
    I am tryning to follow your instruction but get stuck.

    When I run: ./configure –enable-layout=Darwin –enable-mods-shared=all

    I get the message: configure: error: invalid variable name: –enable-layout

    I am a newbee in unix can you please help me?

    Thanks in advance

    Peter

  2. chris responded on 22 Dec 2007 at 10:01 pm #

    Peter,

    I haven’t actually tried these instructions myself - too much trouble when I have a perfectly good Ubuntu machine already running with everything I need. I’d suggest googling for the original source (sorry, I don’t have the link off-hand) and seeing if the author has updated it.

    Cheers.

  3. chris responded on 22 Dec 2007 at 10:16 pm #

    Peter,

    Follow these instructions: http://stringfoo.com/2007/11/07/mamp-setup-leopard/

  4. Peter responded on 23 Dec 2007 at 1:02 am #

    Hi Cris,

    Thanks for the quick reply!

    I will try MAMP as you suggested.

    Have some happy holidays

  5. Mark responded on 01 Mar 2008 at 1:41 pm #

    Peter,

    All of the curly quotes need to be re-typed as just normal double quotes. Similarly, the dashes need to be re-typed as minus signs respectively. For whatever reason the cut and paste formatting here is all messed. Additionally, you will want to change the single dashed flags - to double dashes –. I am specifically referring to the arguments that look like this after a cut and paste:

    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

    Change them to look like this:

    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

    That should do it,
    Mark

  6. Mark responded on 01 Mar 2008 at 1:47 pm #

    Chris,

    Whatever formatter you are using for these postings just messed up my corrections as well in the above comment. So to be more specific, do this replacing every word DASH with a minus character and every QUOTE with a double quote character. Do the same for all messed commands:

    env CFLAGS=QUOTEDASHO DASHg DASHarch i386 DASHarch ppcQUOTE LDFLAGS=QUOTEDASHarch i386 DASHarch ppcQUOTE ./configure DASHDASHprefix=/usr DASHDASHsysconfdir=/etc DASHDASHlocalstatedir=/var DASHDASHmandir=/usr/share/man DASHDASHenableDASHshared DASHDASHenableDASHstatic

    Mark

  7. chris responded on 01 Mar 2008 at 1:49 pm #

    Mark,

    Thanks for the explanation! It appears that something in WordPress internals mucks with double-dashes (that’s a comment indicator for SQL so it’s likely over-zealous injection prevention). I had to manually edit your comment to get them to show up properly.

    I’ve updated the post above as per your comment.

    Cheers
    Chris

  8. Paul Harvey responded on 27 Mar 2008 at 3:14 pm #

    This page is great. It really helped me. After a day or more of trying to solve this problem, I was able to follow your instructions here and get everything working again.

    Thanks so much :)

Trackback URI | Comments RSS

Leave a Reply