UPDATE: Please take a look at this. The below is pretty outdated at this point since Apple shipped PHP 5.3.4 with 10.6.8, and 10.7.0 shipped with 5.3.6. Their script is much spiffier than mine. Thanks!
Apple unfortunately forgot to include freetype support in GD with their stock version of PHP 5.3.0 in 10.6 Server at least up to 10.6.2.
So, there’s some info online about compiling freetype into GD in 10.6, but it doesn’t specifically address 10.6 Server, and it references downloading the PHP 5.3.0 source from Apple’s servers, rather than directly from php.net.
So, here’s the info.
- Create a directory for the src.
sudo mkdir /src
- Chown that over to yourself.
sudo chown username /src
- Change into that directory.
cd /src
- Create pcre directory.
mkdir pcre
- Change into pcre directory.
cd pcre
- Download pcre source.
curl ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.01.tar.gz -O
- Download php5.3.1 source.
curl http://us3.php.net/distributions/php-5.3.1.tar.gz -O
- Download libjpeg-v7 source.
curl http://www.ijg.org/files/jpegsrc.v7.tar.gz -O
- Untar all of the above.
find *.tar.gz -exec tar xfvz {} \;
- Change into pcre source directory.
cd pcre-8.01
- configure pcre.
./configure --disable-shared --enable-static
- Make, and install pcre.
make && make install DESTDIR=/src/pcre/pcre-local
- Change into the jpeg directory.
cd ../../jpeg-7
- Copy some config files into the current directory.
cp /usr/share/libtool/config/config.sub .; cp /usr/share/libtool/config/config.guess .
- Config libjpeg.
export MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch x86_64" \
CXXFLAGS="-arch x86_64" \
LDFLAGS="-arch x86_64" \
./configure --enable-shared - Make, and Make install.
make; sudo make install
- Change directory into PHP source folder.
cd ../php-5.3.1
- Modify line 186 of ./ext/iconv/iconv.c and change #define iconv libiconv to #define iconv iconv
- Configure PHP.
MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch x86_64 -g -Os -pipe"
LDFLAGS="-arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
./configure --prefix=/usr \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--disable-dependency-tracking \
--sysconfdir=/private/etc \
--with-apxs2=/usr/sbin/apxs \
--enable-cli \
--with-config-file-path=/etc \
--with-libxml-dir=/usr \
--with-openssl=/usr \
--with-kerberos=/usr \
--with-zlib=/usr \
--enable-bcmath \
--with-bz2=/usr \
--enable-calendar \
--with-curl=/usr \
--enable-exif \
--enable-ftp \
--with-gd \
--with-jpeg-dir=/usr/local/lib \
--with-png-dir=/usr/X11R6 \
--with-freetype-dir=/usr/X11R6 \
--with-xpm-dir=/usr/X11R6 \
--with-ldap=/usr \
--with-ldap-sasl=/usr \
--enable-mbstring \
--enable-mbregex \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/var/mysql/mysql.sock \
--with-iodbc=/usr \
--enable-shmop \
--with-snmp=/usr \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xmlrpc \
--with-iconv-dir=/usr \
--with-xsl=/usr \
--with-pcre-regex=/src/pcre/pcre-local/usr/local - Make PHP.
export EXTRA_CFLAGS="-lresolv"; make
- Backup your php.ini
sudo cp /private/etc/php.ini /private/etc/php.ini.bak
- Install new PHP
sudo make install
- Restore php.ini, and restart apache.
sudo cp /private/etc/php.ini.bak /private/etc/php.ini; sudo apachectl graceful
All and all, on a new mac mini server, this took about 20-30 minutes. And I now have a working PHP 5.3.1 install, and freetype now works with GD (allowing me to put the captcha back on my contact form under “About”. Good luck!
Reference Links:
tom says
Interesting.
Did you check to see which pcre version php is using after this effort? I followed your instructions and found this:
$ php -i | grep PCRE
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 7.8 2008-09-05
which seems not to be the version downloaded and compiled in is exercise.
staze says
You are right! Hmmm… wonder why.
incolor says
Well, it definitely get’s my captcha image working, but PHPMyAdmin gives this error:
Your PHP MySQL library version mysqlnd 5.0.5-dev – 081106 – $Revision: 289630 $ differs from your MySQL server version 5.0.82. This may cause unpredictable behavior.
staze says
I’m not seeing this error with phpMyAdmin (running 3.2.0), though I am seeing those versions of mysqlnd and mysql server, but I am seeing an mcrypt error. I’ll see if I can re-visit my compilation technique and see what exactly is going on. Probably have to make some changes…
incolor says
Here’s an easy way to add mcrypt. Tested with 10.6 Server: http://michaelgracie.com/2009/09/23/plugging-mcrypt-into-php-on-mac-os-x-snow-leopard-10.6.1/
staze says
As a note… this is a bit obsolete now that Apple has built and included 5.3.1 with 10.6.3 server. Ah well. =)
Christoph says
Not so obsolete at all. As Apple 10.6.3 client still “forgets” to include freetype (aaaaaaaaaarg).
How nice is the brave new (or not so new) it world. You go to sleep with the good feeling that your website works great. You wake up and your display is ruined. What happend? I upgraded my OS… The nicest part is, that my web provider did the same, not on apple, but the display is also ruined, because in the new gd bundle there is an unreleated bug.
Well at least there is staze who allowed me to fix at least part of the mess without spending a couple of nights in front of my screen. Many many thanks indeed.
staze says
Yes, I noticed that my captcha broke when I updated to 10.6.3. I hope to revisit this relatively soon so as to address the below as well.
big says
I read at least 10 guides how to add GD to php / or reinstall php with gd support onto 10.6.x, but
none of them was working / complete.
Your guide is clear, works perfectly! Thanks million times!
However 10.6.3 update broke my GD support. in php info I see GD is enabled, so php.ini was not modified by the update, but in apache log i see errors like:
PHP Fatal error: Call to undefined function imagettftext()
or:
PHP Notice: Undefined index: num in /Library/WebServer/Documents/…
and GD with freetype is not working…
if you happen to know how to fix it, please let me know!
thanx in advance
OS X Server 10.6.3 on MacMini
staze says
The Apple version in 10.6.3 replaced the one we compiled from my instructions, so freetype is no longer there. =( Going back through the instructions should fix this… but an earlier comment mentioned mysqlnd and mcrypt didn’t get updated/included (respectively). So, I really just need to revisit this and get it updated…
stay tuned.
staze says
Thanks for liking it btw. =)
big says
to answer my own question: redoing the complete install by your guide after 10.6.3 update fixed my GD+freetype. it was only 20min.
staze says
Excellent. Thanks for posting back!
andy says
do you know how to do this in php 7.1.13 with osx server 5.4 and high Sierra
please give guide
staze says
I can point you to here: https://php-osx.liip.ch/
But otherwise, no. I moved my hosting to an external host a few years ago, and haven’t had to deal with this since.