Apple's Mac OS X 10.5.x Leopard Server is an easy way to get started with the open source *AMP stack (Apache, PHP, MySQL). Everything can be enabled with a click of the mouse using Apple's easy to use GUI, Server Admin. It's a great thing too, but like all of Apple's products, their is always the small detail that ruins it.
Apple forgot a couple of very important open source modules. In PHP it's GD and mcrypt, while Apache is missing the all important mod_perl2. The following HelpFile will guide you on how to compile and install your very own Apache and PHP without affecting Apple's built in setup. Unfortunately, this means that using Server Admin is out of the question, thankfully we have something called Webmin.
- OS X 10.5 Server
- XCode Tools - Available on the Apple OS X Server Install DVD
- These instructions where tested on an Intel Macintosh, they should however work on PowerPC
- Optional: GNU Wget - How to Install
- Optional: Webmin - What is this?
First of all, we need to download the MySQL client libraries and headers from Apple's website since they are not included with Mac OS X Server 10.5. The following instructions are taken directly off of Apple's knowledge base article located at http://support.apple.com/kb/TA25017?viewlocale=en_US.
- Download the file.
- If the download doesn't automatically produce a folder on your desktop, double-click it to unzip it to a folder named "MySQL-43.binaries" which has a file named "MySQL-43.root.tar.gz" in it (as well as the readme file). Note: Do not double-click/unzip the "MySQL-43.root.tar.gz" file that is within the folder.
- Open Terminal.
- Type cd (but do not press Return).
- Drag the "MySQL-43.binaries" folder from your desktop to the Terminal window to populate the cd path, then press Return.
- Execute this command:
sudo tar -xzvf MySQL-43.root.tar.gz -C /
Make sure you complete this step, you can not build PHP with MySQL support without these libraries and headers.
Lets go to a terminal and switch to the root user and create ourselves a work folder to keep everything in. Execute the following commands in your terminal window:
Build and Install Apache 2.2.x
We will build Apache and install it into "/usr/local/apache2" (the default location). Start by downloading and extracting the latest Apache release from the apache.org website to your work folder. In our example, the latest version was 2.2.14. Notice that we switch to the Apache source code directory.
tar xfvz httpd-2.2.14.tar.gz
Run the configure script with the options to enable all modules as shared, enable ssl, and enable suexec. Then compile and install into the default location (/usr/local/apache2). Finally, switch back to our work folder (cd..).
./configure --enable-mods-shared="all ssl" --enable-suexec
Build and Install Mod Perl 2
We will install mod_perl2 into /usr/local/mod_perl2. Once again download and extract the mod_perl2 source code.
tar -xvzf mod_perl-2.0-current.tar.gz
Generate the make file and tell mod_perl2 that we want to install it into /usr/local/mod_perl2 by using the PREFIX flag. We also need to tell it where to find our Apache 2 installation, this is done with the MP_AP_PREFIX flag. Then build, install, and return to the work directory.
perl Makefile.PL PREFIX=/usr/local/mod_perl2 MP_AP_PREFIX=/usr/local/apache2
This completed the Apache end of things, next we prepare to build PHP, but their are a couple of libraries that we need first.
Build and Install libjpeg
PHP GD depends on the libjpeg library, so lets install this at /usr/local/libjpeg. Download and extract as shown.
tar xfvz jpegsrc.v6b.tar.gz
The configure script will throw an error unless you copy some configuration hints from the libtool library to the libjpeg source files directory. The libtool library is already included in OS X. Execute the following commands to obtain those files.
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
Configure and make, notice how we specify the install directory with PREFIX. You must compile libjpeg with the shared option, thus we use the "--enable-shared" flag.
./configure --prefix=/usr/local/libjpeg --enable-shared
Since this is such an old library, it won't automatically create the destination directories, you must do that manually before attempting to install.
mkdir -p /usr/local/libjpeg/include
mkdir -p /usr/local/libjpeg/bin
mkdir -p /usr/local/libjpeg/lib
mkdir -p /usr/local/libjpeg/man/man1
Now you can install and return to the work folder
Build and Install FreeType2
Some features of the GD library won't be enabled unless you have freetype2 installed. Download, extract, configure, build, and install to "/usr/local/freetype2" as shown.
tar xfvz freetype-2.3.8.tar.gz
Build and Install GD
Download, extract, configure, build, and install libgd to "/usr/local/gd" as shown. Notice how we tell libgd where to find libjpeg and freetype2.
tar xfvz gd-2.0.35.tar.gz
./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/libjpeg --with-freetype=/usr/local/freetype2
Build and Install libmcrypt
Lots of PHP application want mcrypt (phpMyAdmin for example), so lets go ahead and get the mcrypt library setup. PHP recommends that you specify the following flags, "--disable-posix-threads" and "--enable-dynamic-loading".
Download, extract, configure, build, and install to "/usr/local/mcrypt" as shown.
tar xfvz libmcrypt-2.5.8.tar.gz
./configure --prefix=/usr/local/mcrypt --disable-posix-threads --enable-dynamic-loading
Build and Install PHP
It's time to build PHP. There are tons of configure options available, I have selected the most used. You may take a look at all available options by using the "--help" flag when you run the configure script. Keep in mind however, that some options may require additional dependencies not discussed here.
Download and Extract the latest PHP source code
tar xfvz php-5.2.13.tar.gz
Along with the desired features we want PHP to have, we must tell it where to find libgd, mcrypt, Apache, MySQL Client, libjpeg, and freetype2. Additionally, we must tell PHP where to find some of the Apple built in libraries. Thus we have a long and complex configure command as shown.
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr --with-mysql-sock=/var/mysql --with-mysqli=/usr/bin/mysql_config --with-zlib-dir=/usr --with-iodbc=/usr --with-curl=/usr --with-xsl=/usr --with-jpeg-dir=/usr/local/libjpeg --with-gd=/usr/local/gd --with-freetype-dir=/usr/local/freetype2 --with-mcrypt=/usr/local/mcrypt --enable-cli --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-openssl --with-xmlrpc --with-pear
Once PHP's make file is configured, lets build and install
PHP will automatically modify the httpd.conf file in your Apache installation, but it won't add the application type. We'll take care of that part later.
Putting it all together
Our new software is compiled and installed, but it needs to be configured before we can use it. Everything is brought together in the httpd.conf file located in /usr/local/apache2/conf/
Add the following lines to your httpd.conf file:
LoadModule perl_module modules/mod_perl.so
AddType application/x-httpd-php php
The following line should already exist:
LoadModule php5_module modules/libphp5.so
The directives above are the absolute minimum to get everything working. The Apache configuration file is organized in such a way that those directives have an appropriate place in the file. However you are not obligated to place them in the same way, but it does keep you file neat and organized. It's perfectly OK to add the lines to the end of the file.
Once you've made the changes, save the file, and turn off Apple's Apache using Server Admin.
Create a test.php file with the following contents:
Save that file to "/usr/local/apache2/htdocs"
Start your custom Apache by running:
Then test the connection with your web browser by going to "http://localhost/test.php". You should see a PHP information page.
Things to consider
Their are a couple of items that I should mention. Your custom Apache won't start automatically on system boot without a start up script. Apple provides decent documentation on the creation of one, but I may provide my own tutorial in the future. It's not really that difficult, and you could use Webmin to generate the script for you by going into the "boot up and shutdown" menu.
Also bear in mind that your Apple OS X Server will default to using it's built in binaries instead of yours. That means if you execute "apachectl" without using the full path (/usr/local/apache2/bin/apachectl), it will run the Apple built in one. The same applies for PHP.
Lastly, you can't use Server Admin to configure your Apache server. I suggest installing Webmin and using that instead. Installing webmin on OS X 10.5 and later is much more simplified than previous versions. View the HelpFile Installing Webmin on OS X 10.5 Server for complete instructions.
If you decide to use webmin, don't forget to modify the Apache module to point to your custom Apache instead of Apple's built in version. My suggestion is to clone the module, this way you have both available.