<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>AidenWeb - php</title>
    <link>http://www.aidenweb.co.uk/</link>
    <description />
    <language>en-us</language>
    <copyright>Aiden Montgomery</copyright>
    <lastBuildDate>Tue, 18 Nov 2008 14:08:34 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>blog@aidenweb.co.uk</managingEditor>
    <webMaster>blog@aidenweb.co.uk</webMaster>
    <item>
      <trackback:ping>http://www.aidenweb.co.uk/Trackback.aspx?guid=a578df69-78e9-4e28-9a14-f1aa1222a9fd</trackback:ping>
      <pingback:server>http://www.aidenweb.co.uk/pingback.aspx</pingback:server>
      <pingback:target>http://www.aidenweb.co.uk/PermaLink,guid,a578df69-78e9-4e28-9a14-f1aa1222a9fd.aspx</pingback:target>
      <dc:creator>Aiden Montgomery</dc:creator>
      <wfw:comment>http://www.aidenweb.co.uk/CommentView,guid,a578df69-78e9-4e28-9a14-f1aa1222a9fd.aspx</wfw:comment>
      <wfw:commentRss>http://www.aidenweb.co.uk/SyndicationService.asmx/GetEntryCommentsRss?guid=a578df69-78e9-4e28-9a14-f1aa1222a9fd</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <title>Adding GD to PHP on OS X 10.5.5 Leopard (Desktop)</title>
      <guid isPermaLink="false">http://www.aidenweb.co.uk/PermaLink,guid,a578df69-78e9-4e28-9a14-f1aa1222a9fd.aspx</guid>
      <link>http://www.aidenweb.co.uk/2008/11/18/AddingGDToPHPOnOSX1055LeopardDesktop.aspx</link>
      <pubDate>Tue, 18 Nov 2008 14:08:34 GMT</pubDate>
      <description>&lt;h2&gt;Introduction
&lt;/h2&gt;
&lt;p&gt;
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.&lt;br /&gt;
I am working on a MacBook Pro, Intel Core 2 Duo running Mac OS X Version 10.5.5.
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;h2&gt;Disclaimer
&lt;/h2&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;h2&gt;Background Research
&lt;/h2&gt;
&lt;p&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Let me stress that point, this is a note for &lt;b&gt;myself&lt;/b&gt;. 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.
&lt;/p&gt;
&lt;p&gt;
First of all here are some links to people who have already written about the process.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://osx.topicdesk.com/content/view/135/62/" title="" target=""&gt;topicdesk.com&lt;/a&gt; -
A pdf that contains the instructions for adding the GD Extensino to PHP5 on OS X Server
10.5.x&lt;a href="http://www.kenior.com/macintosh/adding-gd-library-for-mac-os-x-leopard"&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.kenior.com/macintosh/adding-gd-library-for-mac-os-x-leopard"&gt;Kenior
Design&lt;/a&gt; - Good instructions with a decent level of detail. Interesting conversations
in the comments.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://90kts.com/blog/2008/installing-gd-libraries-for-leopard-apache-php-525/"&gt;90kts.com&lt;/a&gt; -
A shorthand version of the topicdesk pdf. The comments to this post helped me get
to my solution.&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="clear: both"&gt;
The instructions found in the &lt;a href="http://osx.topicdesk.com/content/view/135/62/"&gt;PDF&lt;/a&gt; from &lt;a href="http://topicdesk.com"&gt;topicdesk.com&lt;/a&gt; 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)
&lt;/p&gt;
&lt;p&gt;
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 (&lt;i&gt;tail /var/log/apache2/error_log&lt;/i&gt;), I discovered this error message.
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
The process has forked and you cannot use this CoreFoundation functionality safely.
You MUST exec().&lt;br /&gt;
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__()
to debug
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Which lead me to these pages that describe what is going on.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://developer.apple.com/releasenotes/CoreFoundation/CoreFoundation.html"&gt;Apple
document&lt;/a&gt; on CoreFoundation and Fork()&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://discussions.apple.com/message.jspa?messageID=5705589"&gt;Apple Support
DIscussion&lt;/a&gt; - Final reply in this thread suggests how to solve the problem.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://90kts.com/blog/2008/installing-gd-libraries-for-leopard-apache-php-525/"&gt;90kts.com&lt;/a&gt; -
Instructions in the comments on how to compile things correctly.&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="clear: both"&gt;
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.&lt;br /&gt;
&lt;br /&gt;
These are the mistakes that I made: -
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
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 &lt;b&gt;64 bit CPU&lt;/b&gt; not a 32 bit.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
Before downloading any of the source code that is listed in these posts, ensure that
you are downloading the version appropriate to your installation.&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;
I am using OS X 10.5.5, most of the references have links to 10.5.4 or earlier.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
My PHP installation is 5.2.6, again the reference material talks about 5.2.5 or earlier.&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Successful Installation
&lt;/h2&gt;
&lt;p&gt;
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 &lt;a href="http://osx.topicdesk.com/content/view/135/62/"&gt;PDF&lt;/a&gt; from &lt;a href="http://topicdesk.com"&gt;topicdesk.com&lt;/a&gt;,
with changes to the download locations). I am including these steps here merely for
completeness. Please refer to their PDF for more information: -
&lt;/p&gt;
&lt;p&gt;
Installing libjpeg was exactly how the &lt;a href="http://topicdesk.com"&gt;topicdesk&lt;/a&gt;&lt;a href="http://osx.topicdesk.com/content/view/135/62/"&gt;pdf&lt;/a&gt; explained.
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
mkdir -p /SourceCache&lt;br /&gt;
cd /SourceCache
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt;
&lt;p&gt;
curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz&lt;br /&gt;
tar xzpf jpegsrc.v6b.tar.gz
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt;
&lt;p&gt;
cd /SourceCache/jpeg-6b&lt;br /&gt;
cp /usr/share/libtool/config.sub .&lt;br /&gt;
cp /usr/share/libtool/config.guess .
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
(This is what I used as it I am installing for my 64 bit CPU)
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
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
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt;
&lt;p&gt;
make&lt;br /&gt;
sudo mkdir -p /usr/local/include&lt;br /&gt;
sudo mkdir -p /usr/local/bin&lt;br /&gt;
sudo mkdir -p /usr/local/lib&lt;br /&gt;
sudo mkdir -p /usr/local/man/man1&lt;br /&gt;
sudo make install
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
(Deviation from the &lt;a href="http://topicdesk.com"&gt;topicdesk.com&lt;/a&gt;&lt;a href="http://osx.topicdesk.com/content/view/135/62/"&gt;PDF&lt;/a&gt;)&lt;br /&gt;
Now we need to get a newer version of &lt;a href="http://freetype.sourceforge.net/"&gt;FreeType&lt;/a&gt; so
that we don't see that horrible error. I chose to use a version from this location &lt;a href="http://download.savannah.gnu.org/releases/freetype/"&gt;http://download.savannah.gnu.org/releases/freetype/&lt;/a&gt; specifically
the 2.3.7 version.
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
cd /SourceCache&lt;br /&gt;
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.7.tar.gz&lt;br /&gt;
tar xvfp freetype-2.3.7.tar.gz&lt;br /&gt;
cd freetype-2.3.7
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This is the important line as it re-compiles &lt;a href="http://freetype.sourceforge.net/" title="" target=""&gt;FreeType&lt;/a&gt; with
these options –with-fsspec=no –with-fsref=no –with-quickdraw-toolbox=no –with-quickdraw-carbon=no&lt;br /&gt;
This prevents &lt;a href="http://freetype.sourceforge.net/"&gt;FreeType&lt;/a&gt; from causing
the Fork() error.
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
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&lt;br /&gt;
&lt;br /&gt;
make&lt;br /&gt;
sudo make install
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
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 &lt;a href="http://www.opensource.apple.com/darwinsource/10.5.5/"&gt;http://www.opensource.apple.com/darwinsource/10.5.5/&lt;/a&gt; to
find the right code to download, and found &lt;a href="http://www.opensource.apple.com/darwinsource/10.5.5/apache_mod_php-44.1/"&gt;http://www.opensource.apple.com/darwinsource/10.5.5/apache_mod_php-44.1/&lt;/a&gt;
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
cd /sourcecache&lt;br /&gt;
curl -O http://www.opensource.apple.com/darwinsource/10.5.5/apache_mod_php-44.1/php-5.2.6.tar.bz2&lt;br /&gt;
tar xjf php-5.2.6.tar.bz2&lt;br /&gt;
cd php-5.2.6/ext/gd&lt;br /&gt;
&lt;br /&gt;
sudo phpize
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
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)
&lt;/p&gt;&lt;blockquote"&gt;
&lt;p&gt;
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 &lt;b&gt;--with-freetype-dir=/usr/local/lib&lt;/b&gt; --with-xpm-dir=/usr/X11R6&lt;br /&gt;
&lt;br /&gt;
make&lt;br /&gt;
sudo make install&lt;br /&gt;
&lt;br /&gt;
sudo apachectl graceful
&lt;/p&gt;
&gt; 
&lt;p&gt;
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.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aidenweb.co.uk/aggbug.ashx?id=a578df69-78e9-4e28-9a14-f1aa1222a9fd" /&gt;</description>
      <comments>http://www.aidenweb.co.uk/CommentView,guid,a578df69-78e9-4e28-9a14-f1aa1222a9fd.aspx</comments>
      <category>development</category>
      <category>OSX</category>
      <category>php</category>
      <category>apache</category>
    </item>
  </channel>
</rss>