Installing Apache 2.0, PHP and Subversion on Mac OS 10.4

After trying to install Django on my Mac and failing, I have decided to try and upgrade my local version of Apache 1.3 to version 2.0. If you are developing on the Mac OS, you may know that Mac OS 10.4 comes with Apache installed on it. While this is one of the great things about the Mac OS, what’s not great is that it is out of date. For most cases when you are developing locally on the Mac, Apache 1.3 is fine. But, you may find that with Apache 1.3 installed, you will not be able to run certain software.

The solution to this is to upgrade to Apache 2.0. I admit that I was reluctant to do this myself, but I found a tutorial from Apple that convinced me to try it. Apache 2.0.61 is the current stable version of the 2.0 series, and that is the version I decided to go with. I downloaded the package and extracted it into /usr/local/src using the following commands.

curl -O http://www.eng.lsu.edu/mirrors/apache/httpd/httpd-2.0.61.tar.gz
tar xvfz httpd-2.0.61.tar.gz
cd httpd-2.0.61
export ac_cv_func_poll=no

Make the following changes to srclib/apr/network_io/unix/sendrecv.c in the apr_socket_send function:

Change:

do {
rv = write(sock->socketdes, buf, (*len));
} while (rv == -1 && errno == EINTR);

To:

try_write: do {
rv = write(sock->socketdes, buf, (*len));
} while (rv == -1 && errno == EINTR);

(That is, add “try_write:” right before the “do {“.)

Replace the following else clause (that is, delete these five lines):

else {
do {
rv = write(sock->socketdes, buf, (*len));
} while (rv == -1 && errno == EINTR);
}

with these two lines:

else
goto try_write;

Run configure, run make, and then run sudo make install to set up Apache 2.0 for installation:

./configure --enable-mods-shared=most --enable-ssl
--with-mpm=worker --without-berkeley-db
make
sudo make install

Create a directory for mod_dav.h, and copy the module to it using the following Terminal commands:

cd /usr/local/apache2
mkdir -p modules/dav/main
cp include/mod_dav.h modules/dav/main/

Once you have it installed, run the following command to start Apache.

sudo /usr/local/apache2/bin/apachectl start

You also need to run the following commands to start Apache 2.0 on each reboot.

sudo -s
mkdir /Library/StartupItems # This directory might already exist
ditto /System/Library/StartupItems/Apache /Library/StartupItems/Apache2
mv /Library/StartupItems/Apache2/Apache /Library/StartupItems/Apache2/Apache2
defaults write /Library/StartupItems/Apache2/StartupParameters Provides -array "Apache2"
perl -p -i -e 's/WEBSERVER/APACHE2/g' /Library/StartupItems/Apache2/Apache2
echo "APACHE2=-YES-" >> /etc/hostconfig

I have a problem now in that turning off and on web sharing in the system preferences will not stop and start Apache 2.0. I am at a loss on how to make this work. I am also unsure whether or not Apache 2.0 will start on reboot or whether I have to start it manually.

Subversion is rather easy to install. I used the tutorial found at hivelogic along with the same one I used to install Apache 2.0. Subversion appears to be installed and working but I haven’t really tested it in depth.

Once I had Apache 2.0 installed, I wanted to be able to access it when I go to http://localhost/ and access the files in /Library/Webserver/Documents. You need to stop Apache and then edit the http.conf file found in /usr/local/apache2/conf/httpd.conf. Then you need to change the DocumentRoot and the Directory.

DocumentRoot "/Library/Webserver/Documents"
<Directory "/Library/Webserver/Documents">

Now you can restart Apache and you should be able to access Apache 2.0 on http://localhost/. However, I found that PHP was no longer working because I had not yet installed it for Apache 2.0. Don’t worry though all you have to do is recompile it. Here are the steps I used.

If you already have the php files on your machine, go into that directory.

cd /usr/local/src/php-4.4.7

If not download it and unpack it again and then go into the directory you just created. Now you need to create the directory to install PHP into.

sudo mkdir /apache2/php

Then all you need to do is configure it with the right options. I used the following commands which adds support for the GD graphics library, in addition to mysql.

./configure --prefix=/usr/local/apache2/php
--with-zlib-dir=/usr/local/lib
--with-jpeg-dir=/usr/local/lib
--with-png-dir=/usr/local/lib
--with-gd --with-mysql=/usr/local/mysql
--with-apxs2=/usr/local/apache2/bin/apxs
make
sudo make install

I ran into problems doing this. I kept getting the error from mysql.

dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib

I fixed this by copying the file into that path using the following commands.

cd /usr/local/mysql/lib
mkdir mysql
cp libmysqlclient.15.dylib mysql/libmysqlclient.15.dylib

I ran configure, make, sudo make install again, and it worked. An optional step you may want to take is to create a php.ini file. I created the php.ini file with this command.

sudo cp php.ini-dist /apache2/php/lib/php.ini

Now we need to edit the http.conf again so that PHP will run in Apache. Add the following lines in the appropriate sections.

LoadModule php4_module modules/libphp4.so
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php

Now restart Apache 2.0. Once I did that it worked. I now have Apache 2.0, PHP 4.4.7 and Subversion 1.3 installed locally on my Mac.

Disclaimer: Your mileage may vary. This is the compilation of a lot of work over a period of several days. I have tried to recount the steps I used as closely as possible. Use at your own risk. Here are some tutorials you may want to look at if you get stuck. Good luck.

Building and Installing Apache 2.2.4 and PHP 5.1.4 on Mac OS X 10.4.6
Apache 2.0 on Unix systems