« The web's most obtuse download | Main | How do you recycle a TV? »

Installing Apache 2.2, PHP 5, and Subversion 1.4 on a Mac Mini

…and making them all play nicely together.

Something about the error messages I was getting made me decide I might have better luck with Apache 2.2. I used 2.0.x before, so I was a little apprehensive about being on the bleeding edge for all these packages, but since so much of the documentation I was following looks at older versions, I was a bit at sea about the proper way to configure the newer versions. (This Ruby, Rails, etc. tutorial, which was the initial Subversion installation, is pretty up to date on versions, but Apple’s documentation for Apache 2, PHP, and the Subversion bridge is four or five years old, and shows it.) Most of this is derived from instructions other people wrote up, and to them I am grateful… but I still had to do a chunk of this myself.

So here’s how I did it. Everything is installed from source, with the tarballs living in /usr/local/src/ and most of the binaries being installed in /usr/local/ somewhere. The installation sequence goes pretty much like this: Apache, Subversion, PHP, WebSVN.

In a perfect world, I’d have all my friendly binaries and could use wget, which I prefer, to do downloads, but I’m going to try to assume pretty close to an off-the-shelf Mac. This one is running OS 10.4.9, and the only non-standard software installed which affects this process are the databases, MySQL and Postgres, which you can install separately using packages from Marc Liyanage, and BerkeleyDB, which you can install from source if you’re willing to navigate Oracle’s website to find the documentation, but I’m not sure I did right anyway. You may need to prefix some of these commands with sudo depending on the permissions set in your /usr/local/src directory; almost every make install command will require sudo.

Naturally, this is just the process that worked for me. I expect it will still work for bug-fix releases of these packages, but for anything that’s a minor version number away, your mileage may vary.

Technorati Tags: , , , , , ,

Apache 2.2.4

The Apache installation turns out to be the simplest, but requires some of the most configuration futzing.

If the download link doesn’t work, try the downloads page for other mirrors.

curl -O http://www.devlib.org/apache/httpd/httpd-2.2.4.tar.bz2
tar xjvf httpd-2.2.4.tar.bz2
cd httpd-2.2.4

Here, you have to stop and actually edit source files, according to Apple. Edit srclib/apr/network_io/unix/sendrecv.c and look in the apr_socket_send function.

Replace

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

with

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

(As Apple notes, all you’re really doing is adding “try_write:” before the “do”.)

Then delete these five lines:

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

and replace them with this:

else
    goto try_write;

Now you can go back to the root of the source directory, configure, make, make install.

./configure --enable-mods-shared=most \
    --enable-ssl --with-mpm=worker \
    --with-berkeley-db=/usr/local/BerkeleyDB.4.5/lib
make
sudo make install

Finally, you need to move the mod_dav module to the right place. We’ll be doing a lot more configuring of Apache later, so don’t try starting it up just yet.

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

Subversion 1.4

There’s room for debate about which version of Subversion to use. If you have an established repository, going with the more-stable 1.3.x is probably the way to go, since 1.4 is supposed to be incompatible with older repositories. I’m starting from scratch, and there’s no point in bringing the “it’s time to update Subversion” point any closer than it needs to be, so 1.4 it is.

The rest of this is fairly tediously predictable:

curl -O http://subversion.tigris.org/downloads/subversion-1.4.3.tar.bz2
tar xjvf subversion-1.4.3.tar.bz2
cd subversion-1.4.3
./configure --prefix=/usr/local \
    --mandir=/usr/local/share/man \
    --with-ssl --with-openssl --with-zlib \
    --enable-swig-bindings=no \
    --with-apxs=/usr/local/apache2/bin/apxs 
make
sudo make install
cd ..

At this point, you should have the software needed to do Subversion checkins and checkouts over http. You just need to configure Apache to talk to Subversion. Edit /usr/local/apache2/conf/httpd.conf (if you have TextWrangler and its command-line utilities installed, you can literally type edit /usr/local/apache2/conf/httpd.conf) and make these changes:

Listen 80

to

Listen 8080

(This is so Apache2 won’t contend with the default Apache for the standard HTTP port.)

Add:

LoadModule dav_svn_module    modules/mod_dav_svn.so
LoadModule authz_svn_module  modules/mod_authz_svn.so

and

<Location /svn>
    DAV svn
    SVNPath /Users/me/Documents/Code
</Location>

What I’ve done here is tell Apache that the SVN repository is located at /Users/me/Documents/Code. You’ll need to tell Subversion there’s a repository there: use svnadmin create /Users/me/Documents/Code and start Apache using /usr/local/apache2/bin/apachectl start. Finally, the directory your repository lives in should be owned by the same user that Apache runs as. On my Mini, that’s “daemon” (use ps -aux | grep "httpd" to check yours) so sudo chown -R daemon /Users/me/Documents/Code and you should be good to go.

PHP 5.2.1

It’s tempting to use Marc Liyanage’s PHP package here, but don’t; it is set up to work with your default Apache 1.3, and won’t affect your Apache 2.0. (It’s possible to install to both Apaches from one source tarball, but it requires compiling two different modules.) Instead, we’re (sigh) installing from source. It’s not really that painful; it’s certainly possible to build a truly massive ./configure line for PHP, but we’re not trying to be web hosts here, just to support WebSVN (which comes next).

PHP makes it non-intuitive to create a direct download link for curl, so use your browser to download from here and, if you’re working remotely, upload the tarball using scp. Then, assuming we’re back in /usr/local/src/

tar xjvf php-5.2.1.tar.bz2
cd php-5.2.1
./configure --with-apxs2=/usr/local/apache2/bin/apxs \
    --with-mysql=/usr/local/mysql \
    --with-apr=/usr/local/apache2 \
    --with-apr-util=/usr/local/apache2 \
    --with-zlib

(Note APR notes after the WebSVN section.)

make
sudo make install

Now you need to edit /usr/local/apache2/conf/httpd.conf again. Add these lines:

LoadModule php5_module    modules/libphp5.so

(The PHP installation process may have added this for you.)

Change

DirectoryIndex index.html

to

DirectoryIndex index.html index.php

and add

AddType application/x-httpd-php .php

Now restart Apache with /usr/local/apache2/bin/apachectl graceful and if everything has gone well, PHP should be available.

WebSVN

This one isn’t a simple download-and-untar installation.

cd /usr/local/apache2/htdocs
mkdir websvn
svn checkout http://websvn.tigris.org/svn/websvn/tags/1.62 websvn --username guest

That’s the whole installation, but you need to do some configuring.

cp websvn/include/distconfig.inc websvn/include/config.inc

Now edit websvn/include/config.inc. You can manually configure the paths to svn (/usr/local/bin) and commands like diff, enscript, sed, tar and gzip if you wish (use e.g. which enscript to find the path to the command) but the important part is the repository setup. At the end of the “REPOSITORY SETUP” section, un-comment the line starting $config->parentPath and fill in your repository path:

$config->parentPath("/Users/me/Documents/Code")

Now, you should be able to hit WebSVN by going to http://localhost:8080/websvn/.

This is as far as I’ve made it. I’m still getting some errors from WebSVN, and I need to know more about Subversion to really make more progress. (Update: Some of the errors came from compiling PHP without zlib. I added that to the configuration above.)

A note about APR

If you get errors in the process regarding APR, you can download apr and apr-util and install them:

curl -O http://apache.cs.utah.edu/apr/apr-1.2.8.tar.bz2
curl -O http://apache.cs.utah.edu/apr/apr-util-1.2.8.tar.bz2
tar xjvf apr-1.2.8.tar.bz2
tar xjvf apr-util-1.2.8.tar.bz2
cd apr-1.2.8
./configure --prefix=/usr/local
make
sudo make install
cd ../apr-util-1.2.8
./configure --prefix=/usr/local --with-apr=/usr/local/apr
make
sudo make install

then you can go back and re-run the installations of Apache, Subversion, and PHP starting by issuing make clean and then picking up the process with ./configure, adding flags like this to the ./configure lines:

--with-apr=/usr/local/apr

…and that may fix things. I tried this at some point in the process, but I think Apache 2.2 comes with a 1.x APR anyway, which means these problems shouldn’t come up.

Post a comment