I got tired of looking for a way to replace the Apache/PHP that Apple packages with OS X (without breaking anything else in the process) so I decided to install Apache 2.2 and PHP5 in their own location to avoid stepping on the Apple package toes.
Since I do a great deal of development again MySQL I needed to install that as well, and figured that I would probably need the GD functionality as well so I grabbed libjpeg and libpng to make those work as well. This is the step-by-step.
(Props to James Pelow and his article from last year, from which I borrowed the configure command lines and configuration modifications, as well as the idea of installing the whole mess in /apache2.)
Download the latest MySQL (I used the package version) from MySQL.
Installation is straightforward following the same methods as any other Mac installer.
Download and install libjpeg and libpng – from Ethan Tira-Thompson (this is also in a Mac installer which contains both libraries in one installer).
Download the latest Apache httpd server (Unix source) from Apache
in the terminal:
tar -xzvf httpd-2.2.6.tar.gz && cd httpd-2.2.6
./configure
--prefix=/apache2
--enable-module=most
--enable-shared=max
make
sudo make install
sudo mkdir /apache2/php
Download the latest PHP from PHP
tar -xzvf php-5.2.4.tar.gz && cd php-5.2.4
./configure
--prefix=/apache2/php
--with-zlib
--with-xml
--with-ldap=/usr
--enable-cli
--with-zlib-dir=/usr
--enable-exif
--enable-ftp
--enable-mbstring
--enable-mbregex
--enable-dbx
--enable-sockets
--with-iodbc=/usr
--with-curl=/usr
--with-mysql=/usr/local/mysql
--with-gd
--with-jpeg-dir=/usr/local
--with-png-dir=/usr/local
--with-apxs2=/apache2/bin/apxsmake
sudo make install
sudo cp php.ini-dist /apache2/php/lib/php.ini
Now to make your Apache2.2 a little more ‘Mac’ – you can point it at the Mac web shared files folder, change the user and group and change the location for user files to match the Mac folder system.
Edit httpd.conf (I use nano, you can use any flat text editor like nano, pico, vi, emacs or even BBedit)
sudo nano -w /apache2/conf/httpd.conf
The changes to httpd.conf I made:
I changed
User daemon
Group daemon
to
User www
Group www
and
DocumentRoot "/apache2/htdocs"
to
DocumentRoot "/Library/WebServer/Documents"
and
<Directory "/apache2/htdocs">
to
<Directory "/Library/WebServer/Documents">
and added
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php
Edit httpd-userdir.conf
sudo nano -w /apache2/conf/extra/httpd-userdir.conf
The changes to httpd-userdir.conf I made:
I changed
UserDir public_html
to
UserDir Sites
To start and stop the server:
MySQL comes with a Preference Pane that allows you to start and stop it there. To start and stop Apache you need to first make sure that the default Apache shipped with OS X is stopped.
sudo /apache2/bin/apachectl start
sudo /apache2/bin/apachectl stop
I only ran into one issue, when trying to start the server I ran against the following error message (and no running server, of course):
httpd: Syntax error on line 53 of /apache2/conf/httpd.conf:
Cannot load /apache2/modules/libphp5.so into server:
Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
Referenced from: /apache2/modules/libphp5.son Reason: image not found
To fix this I did the following:
cd /usr/local/mysql/lib
sudo mkdir /usr/local/mysql/lib/mysql
for i in `ls ./l*`; do sudo ln -sf /usr/local/mysql/lib/$i /usr/local/mysql/lib/mysql/$i; done
This creates soft links in the directory that libphp5.so is looking for the MySQL libraries.
Then it started right up! Wheee! (I did a quick test by dropping PhpMyAdmin into the /Library/WebServer/Documents folder and browsed to it – the whole Apache/PHP/MySQL is working correctly)
Technorati Tags: Apache 2.2, PHP5, MySQL 5, OS X