Adding GD to PHP on OS X 10.5.5 Leopard (Desktop)

Posted on 18th November 2008 in apache, development, OSX, php

Introduction

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.

Disclaimer

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.

Background Research

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.
    1. I am using OS X 10.5.5, most of the references have links to 10.5.4 or earlier.
    2. My PHP installation is 5.2.6, again the reference material talks about 5.2.5 or earlier.

Successful Installation

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
cd /SourceCache

curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar xzpf jpegsrc.v6b.tar.gz

cd /SourceCache/jpeg-6b
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

make
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.

cd /SourceCache
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.7.tar.gz
tar xvfp freetype-2.3.7.tar.gz
cd freetype-2.3.7

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

make
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/

cd /sourcecache
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
cd php-5.2.6/ext/gd

sudo phpize

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

make
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.

comments: 4 »

Moving to the Mac

Posted on 3rd August 2008 in OSX, Software

Background

A few months ago I was in need of a new laptop. My current Sony Vaio was starting to struggle running Visual Studio 2005/2008, IIS and MSSQL 2005 all at once.

So I started looking around for a replacement. Whilst reading reviews and generally searching for recommended development laptops, I started noticing a number of articles that were claiming that the Mac Book Pro was the fastest Windows XP laptop out there.

At the time our company was thinking of developing an iPhone version of our mobile phone software and I wanted to find out what it was like living in a non Windows OS. I have worked almost exclusively on Windows platforms since leaving Sixth Form in 1999 (wow that seems a long time ago). So I decided to give OSX a try.

When I told some of my friends they thought that I had gone mad, after all I use my laptop for work and my job is developing software. Which isn’t an issue until you find out that I build ASP.net websites and Winforms applications in C#.

Finding Applications

The first thing that I did was try and figure out the applications that I would need for everyday use of Leopard. Everyday tasks on a Windows XP machine would see me using the following applications: -

  1. Email – Outlook
  2. Calendar – Outlook
  3. Web Browser – FireFox or IE
  4. Text editing – Notepad++
  5. Instant Messaging – Windows Live Messenger
  6. Application Launching – SlickRun
  7. Note taking – Jot (Part of SlickRun) or Microsoft OneNote
  8. Playing Media – Windows Media Player, Media Player Classic or when I synced my iPod, iTunes
  9. IRC – mIRC
  10. VOIP – Skype
  11. RSS Aggregator – FeedDemon
  12. PDF Viewer – Adobe Acrobat Reader
  13. Blogging – Windows Live Writer
  14. FTP – FileZilla
  15. Screen Shots -Cropper
  16. Task Manager
  17. Remote Desktop – Microsoft Terminal Service Client
  18. Virtual Machine – Microsoft Virtual PC
  19. Document editing – Microsoft Office 2007

I spoke to some friends about what they used on the Mac, played with different applications that were out there and came up with the following list of replacements.

  1. Email – Mac Mail*
  2. Calendar – iCal* and Google Calendars
  3. Web Browser – FireFox, Safari* and I also added Camino to the list of browsers [Update:27/01/2009 - More and more I am turning to Opera as my default browser]
  4. Text Editing – TextWrangler [Update:27/01/2009 - Took the plunge and purchased TextMate and using it all of the time now]
  5. Instant Messaging – Adium (Multiple IM client support. I use it for MSN and ICQ)
  6. Application Launching – QuickSilverLaunchbar
  7. Note taking – Stickies* and Evernote YoJimbo
  8. Playing Media – iTunes* and QuickTime* + Perian
  9. IRC – Colloquy
  10. VOIP – Skype
  11. RSS Aggregator – NetNewsWire
  12. PDF Viewer – Preview*
  13. Blogging – Blogo (Also used for twitter)
  14. FTP – CyberDuck (Free), Transmit (Commercial) [Update:27/01/2009 - Using FileZilla all the time now, recent updates have made it stable enough for me to use]
  15. Screen Shots – Grab*
  16. Activity Monitor
  17. Remote Desktop – CoRD
  18. Virtual Machine – VMWare Fusion
  19. Document Editing – Neo Office

Extra applications

There other applications that I have installed which I find very useful.

  1. Growl
  2. smcFanControl
  3. SynergyKM
  4. AppZapper
  5. Delicious Library

Growl allows applications to plug into its API and use it for notifications. The notifications are then controlled by growl and the growl menu. It is possible to configure how notifications behave, how they look, how long they stay on screen and many other aspects. It also appears that notifications can be sent and received across the network, but I have not used this feature.

The second is smcFanControl because my Mac Book Pro didn’t seem to want to spin its fans very fast and tended to get very very hot. smcFanControl allows the user to set fan speeds and have profiles setup for easy switching.

It took me a while to find a working Synergy client for Leopard, however SynergyKM works excellently. I have Synergy running in server mode on a Windows Vista 64bit desktop machine, a Synergy client running on an XP laptop and finally SynergyKM running on this Mac Book Pro. This allows me to use the Keyboard and Mouse from the Vista machine, to drive all 3 machines. When my mouse hits the edge of my monitor, it jumps over to the next machine and takes the keyboard focus with it.

AppZapper is an application uninstaller that will remove all traces of the application you are attempting to remove. It always seems that an Operating System slows down after a number of months being used. This is normally because it is filling up with useless files and (in the case of Windows) registry settings. Many applications fail to uninstall themselves entirely, leaving trace elements behind in temporary files, settings and user data. AppZapper is the way to avoid this happening on your Mac.

Delicious Library lets you use the built in iSight camera to scan barcodes on your stuff. It then uses Amazon to search for the barcode and enter whatever information it can find about you things. It displays your things on shelves using images downloaded from Amazon or ones that you have assigned. Makes it quick to find out if you have something before buying it again. I managed to scan 327 DVDs and 134 books into the application in a couple of hours.

Development Applications

Normally I would install applications directly into my Windows XP installation to allow for .net software development. However on the Mac Book Pro I don’t have the option to install the framework and the development tools. Ok, so I could install Eclipse or TextMate and the mono framework and develop that way, but I need to use the full Microsoft.NET framework for my work.

I am using VMWare Fusion as a virtualization environment. This allows me to run Windows operating systems in a Virtual Machine(VM) on my Mac Book Pro, then simply take the image of the VM over to my Windows machine when I need to and run it there. I will detail my VMWare Fusion setup in another post.

Applications I found whilst researching this post

Whilst looking for links for this post I came across a number of other applications that I am going to try out. I’ll post again sometime soon with my thoughts on them.

FanControl – Like the name suggests, this is another application for controlling the fans. [Update:27/01/2009 - This is now setup as my fan control software.]
AppFresh – Keeps all of your applications up to date. Checks various update sites. [Update:27/01/2009 - I am enjoying this application, it makes keeping things up to date so simple.]
Deeper – Allows access to otherwise hidden preferences.
OnyX – A multifunction utility for Mac OS X 10.5. [Update:27/01/2009 - I use this periodically to tweak setting on my MBP]
Maintenance – A System Maintenance and Cleaning utility for Mac OS X.
FileZilla – OSX Version of FileZilla is available, can’t believe I missed this.
SuperDocker – Allows to customize parts of your Mac OS X Leopard.
LiteIcon – A simple app which allows you to change your system icons easily.
DVDHunter – A free DVD cataloguing application.
VideoLan – Media player and can be used as a streaming server.

Links

http://www.coolosxapps.net/

http://damieng.com/blog/tag/mac-freeware/
http://simpable.com/software/mac-software/

comments: Comments Off