I am trying to help out on a cakePHP project for a friend. One of the things that has been added recently was a phpCaptcha component. This component uses the GD module to create images using text. Of course everything works fine on the test website, but not on my machine.
I am working on a MacBook Pro, Intel Core 2 Duo running Mac OS X Version 10.5.5.
This is mainly for my own memory, as it took me a few hours to get this working, when it should have only taken a few minutes.
If anyone actually finds this page and follows the instructions on it, you do so at you’re own risk. Backup your system before you start. Please follow the information provided by topicdesk.com. The information here worked on my system, on 18th November 2008, it may or may not work for you. If something goes wrong, I will not be able to fix it for you. I will accept no responsibility for any use of this information.
There are a number of tutorials out there that already deal with this issue, the ones that I found were either slightly out of date, or missed something. So rather than have to go through the discovery process again I am leaving myself a note here.
Let me stress that point, this is a note for myself. Other people who know far more about OS X/Apache/PHP than me have written excellent articles, which have helped me get to this point.
First of all here are some links to people who have already written about the process.
- topicdesk.com – A pdf that contains the instructions for adding the GD Extensino to PHP5 on OS X Server 10.5.x
- Kenior Design – Good instructions with a decent level of detail. Interesting conversations in the comments.
- 90kts.com – A shorthand version of the topicdesk pdf. The comments to this post helped me get to my solution.
The instructions found in the PDF from topicdesk.com got me as far as installing GD and editing my php.ini file, which meant that GD was listed in phpinfo(). (Instructions on how to use phpinfo are in the pdf from topicdesk.com)
At this point I thought that I was home and dry, however this wasn’t the case. When trying to access a captcha image I was still not seeing anything. Checking my apache error log (tail /var/log/apache2/error_log), I discovered this error message.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug
Which lead me to these pages that describe what is going on.
With all these sources of information at hand I went ahead and tried to follow the steps outlined, and failed. The mistakes were simple ones, but for someone who is not used to working from the OS X command line, I am sure they are not uncommon.
These are the mistakes that I made: -
- When building the various downloads, ensure that you are building for the correct architecture, or build for multiple platforms. My MacBook Pro has an Intel Core 2 Duo, which is a 64 bit CPU not a 32 bit.
- Before downloading any of the source code that is listed in these posts, ensure that you are downloading the version appropriate to your installation.
- I am using OS X 10.5.5, most of the references have links to 10.5.4 or earlier.
- My PHP installation is 5.2.6, again the reference material talks about 5.2.5 or earlier.
So these are the command lines instructions that I used to successfully install GD into PHP 5.2.6 on Mac OS X Leopard 10.5.5 (Most of this is identical to the PDF from topicdesk.com, with changes to the download locations). I am including these steps here merely for completeness. Please refer to their PDF for more information: -
Installing libjpeg was exactly how the topicdeskpdf explained.
mkdir -p /SourceCache
curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar xzpf jpegsrc.v6b.tar.gz
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
(This is what I used as it I am installing for my 64 bit CPU)
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” ./configure –enable-shared
sudo mkdir -p /usr/local/include
sudo mkdir -p /usr/local/bin
sudo mkdir -p /usr/local/lib
sudo mkdir -p /usr/local/man/man1
sudo make install
(Deviation from the topicdesk.comPDF)
Now we need to get a newer version of FreeType so that we don’t see that horrible error. I chose to use a version from this location http://download.savannah.gnu.org/releases/freetype/ specifically the 2.3.7 version.
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.7.tar.gz
tar xvfp freetype-2.3.7.tar.gz
This is the important line as it re-compiles FreeType with these options –with-fsspec=no –with-fsref=no –with-quickdraw-toolbox=no –with-quickdraw-carbon=no
This prevents FreeType from causing the Fork() error.
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” ./configure –with-fsspec=no –with-fsref=no –with-quickdraw-toolbox=no –with-quickdraw-carbon=no
sudo make install
Then we get back to the topicdesk PDF. Again my versions of PHP and OS X are different from the ones that they are referring to, so I went looking here http://www.opensource.apple.com/darwinsource/10.5.5/ to find the right code to download, and found http://www.opensource.apple.com/darwinsource/10.5.5/apache_mod_php-44.1/
curl -O http://www.opensource.apple.com/darwinsource/10.5.5/apache_mod_php-44.1/php-5.2.6.tar.bz2
tar xjf php-5.2.6.tar.bz2
This next line introduces another change, in that I am now linking to the newly compiled FreeType library, not the pre-installed version. (–with-freetype-dir=/usr/local/lib)
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” ./configure –with-zlib-dir=/usr –with-jpeg-dir=/usr/local/lib –with-png-dir=/usr/X11R6 –with-freetype-dir=/usr/local/lib –with-xpm-dir=/usr/X11R6
sudo make install
sudo apachectl graceful
Finished! Wasn’t so bad after all. Remember the configure options that I have used here are because I am compiling on a 64 bit CPU. I imagine that I could change some of those compilation options to simply create the 64 bit option, but as I was following other tutorials to get this done, I didn’t want to stray off the path even further than I had to.