The Post

Setting up Apache, MySQL and PHP 5 with GD support on Leopard

Before we start...

This tutorial brings you a concise record of how to build from source  Apache 2, MySQL and PHP 5, with GD and FreeType support on Mac OS X 10.5 (Leopard). I gathered the information for this tutorial from various online sources, referenced at the appropriate place in the text.

The tutorial is designed so you will end up with self-contained versions of the Apache Web server, MySQL database server and the PHP scripting language, installed in /usr/local so that if you want to remove these installs in a later date, the won't break your system.

For the sake of keeping this tutorial as short as possible, I have excluded any instructions on how to configure Apache, PHP and MySQL, except for the configuration needed to enable PHP support in Apache.

I case you're running a PPC-based Mac, please replace the gcc environment flags referencing the i386 architecture with PPC. For example, env ARCHFLAGS="-arch i386" should be replaced with env ARCHFLAGS="-arch ppc" where appropriate.

Please be sure to back up any valuable information you have on your computer in case you're afraid of breaking anything during compiling, and of course, be sure to read the license distributed with the downloaded source code before installing it on your computer.

Finally, wherever you see the "%" sign, it means that you should run the command following that sign in your Terminal application (without the "%" of course).

1. Setting up the build environment

If you haven't installed XCode and Leopard's Developer's Tool Kit, now would be a good time to do so. Simply insert Leopard's install DVD, open it in Finder and install Xcode Tools from the "Optional Install" folder

We're going to compile all the source code in /usr/local/src , so lets start by creating this directory.

Open up your terminal (Applications > Utilities > Terminal) and run the following commands:

% cd /usr/local
% sudo mkdir src
% sudo chmod -R 0777 src
% cd src

Now, lets add some important directories to your PATH environment variable so that the compiler finds them during the build process.

% nano ~/.bash_login

Add the following line to the end of the file: export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

Exit the editor and run: % export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

2. Installing Apache 2.2.6

% cd /usr/local/src
% curl -O http://mirror.inter.net.il/mirrors/apache/httpd/httpd-2.2.6.tar.gz
% tar -xvf httpd-2.2.6.tar.gz
% cd httpd-2.2.6
% env CFLAGS="-O -g -arch i386" LDFLAGS="-arch i386" ./configure --prefix=/usr/local/apache2 --enable-modules=all --enable-mods-shared=all --enable-so
% make
% sudo make install

Now that we have Apache installed, lets back up Leopard's Apache binaries and sym-link our newly installed binaries in their stead. This way, we can start up our Apache install from Leopard's Web Sharing pane, and keep our system in tact in case it gets updated or if we want to revert to the original install that came with it.

% sudo mv /usr/sbin/apachectl /usr/sbin/apachectl-orig
% sudo mv /usr/sbin/httpd /usr/sbin/httpd-orig
% sudo ln -s /usr/local/apache2/bin/apachectl /usr/sbin/apachectl
% sudo ln -s /usr/local/apache2/bin/httpd /usr/sbin/httpd

Please note that for these changes to take effect, you'd need to restart your system.

3. Installing MySQL 5

% cd /usr/local/src
% curl -O http://mysql.he.net/Downloads/MySQL-5.0/mysql-5.0.45.tar.gz
% tar xzvf mysql-5.0.45.tar.gz
% cd mysql-5.0.45
% CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared
% make
% make install
% cd /usr/local/mysql
% sudo ./bin/mysql_install_db --user=mysql
% sudo chown -R mysql ./var

Instructions taken from http://hivelogic.com/narrative/articles/installing-mysql-on-mac-os-x

4. Installing PHP5 with GD and FreeType support

This part of the installation is the most complicated as it requires us to install a few libraries required by GD, before installing the GD library and finally PHP.

For our installation to be completely self-contained, we need to create a mini directory architecture into which we'll install all relevant libraries.

% cd /usr/local
% sudo mkdir php5 php5/bin php5/lib php5/man php5/man/man1 php5/include

4.1 Installing libjpeg

% cd /usr/local/src
% curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
% tar -xvf jpegsrc.v6b.tar.gz
% cd jpeg-6b/
% cp /usr/share/libtool/config.sub .
% cp /usr/share/libtool/config.guess .
% env CFLAGS="-O -g -arch i386" LDFLAGS="-arch i386" ./configure -prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --enable-shared --enable-static
% make
% sudo make install

4.2 Installing libpng

% cd /usr/local/src
% curl -O http://prdownloads.sourceforge.net/libpng/libpng-1.2.23.tar.gz?download
% tar -xvf libpng-1.2.23.tar
% cd libpng-1.2.23
% env CFLAGS="-O -g -arch i386" LDFLAGS="-arch i386" ./configure  -prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --enable-shared --enable-static
% make
% sudo make install

4.3 Installing FreeType

% cd /usr/local/src
% curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz
% tar -xvf freetype-2.3.5.tar.gz
% cd freetype-2.3.5
% env CFLAGS="-O -g -arch i386" LDFLAGS="-arch i386" ./configure  -prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --enable-shared --enable-static
% make
% sudo make install

4.4 Installing GD

% cd /usr/local/src
% curl -O http://www.libgd.org/releases/gd-2.0.35.tar.gz
% tar -xvf gd-2.0.35.tar.gz
% cd gd-2.0.35
% env CFLAGS="-O -g -arch i386" LDFLAGS="-arch i386" ./configure -prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --enable-shared --enable-static --with-png=/usr/local/php5 --with-freetype=/usr/local/php5 -with-jpeg=/usr/local/php5
% make
% sudo make install

4.5 Installing PHP

Download from http://www.php.net/downloads.php and extract to /usr/local/src

% cd /usr/local/php-5.2.5
% ./configure -prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-curl --enable-exif --enable-fastcgi --enable-zip --with-jpeg-dir=/usr/local/php5 --with-png-dir=/usr/local/php5 --with-freetype-dir=/usr/local/php5 --with-gd=/usr/local/php5 --enable-ftp --enable-sockets --with-iodbc=/usr --with-config-file-path=/etc --with-openssl --with-xmlrpc --with-xsl=/usr --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp --with-mysqli=/usr/local/mysql/bin/mysql_config
% make
% sudo make install
% cp php.ini-recommended /etc/php.ini

To enable PHP support in Apache, please open httpd.conf:

% sudo /usr/local/apache2/conf/httpd.conf

Add the following lines at the end of the loaded modules list:

LoadModule php5_module modules/libphp5.so
<IfModule mod_php5.c>
    AddType application/x-httpd-php .php
    DirectoryIndex index.php
    PHPIniDir /etc
</IfModule>

* Restart Apache to apply these changes

libpng, libjpeg and PHP instructions are based on instructions found on:
http://www.postal-code.com/binarycode/2007/11/12/leopard-also-breaks-php/
http://www.afp548.com/article.php?story=20041104230209410

5. Final notes

Hopefully you should now have the following installed on your system:

  • Apache 2.2.6 on /usr/local/apache2
  • MySQL 5.0.45 on /usr/local/mysql
  • PHP 5.2.5 with GD-2.0.35 and FreeType-2.3.5 on /usr/local/php5
         

The Posts

 

Oops... Looks like you're using a very old version of Internet Explorer, which we're unable to support.
If you'd like to enjoy this site, please consider using a more modern browser, like: