Your options for running Apache on Mac OS X

For a quick and easy development platform on Mac OS X, Vincent Danen recommends two packages that extend what Apple provides. Learn more about MAMP and XAMPP for running Apache on OS X.

OS X makes for a great development platform, because of it's UNIX core, and the fact that it is built on and includes many open source software libraries and packages. If you do web development, or development with any open source software or languages, chances are you can do your development on a Mac, then deploy it on another Mac or Linux system.

For web developers, having access to a test-bed system, locally, makes web development easy. If the desktop or laptop used for development is a Mac, all of the popular tools are available for use. For instance, OS X comes with the Apache web server and PHP included (with OS X 10.6.4 this includes Apache 2.2.14 and PHP 5.3.1). If you are not using OS X Server, the built-in server and PHP stack is pretty much geared to simple web page sharing and Bonjour, so if you are looking for something a little more standard that provides other features (such as virtual host support, SSL support, and others), what Apple provides may not be enough. As well, Apple does not bundle MySQL with OS X.

There are a few routes that can be taken. You can use Fink to install the missing bits and rely on what Apple provides (or download MySQL for OS X direct from MySQL's web site). This is a viable route to take, certainly, but for simplicity's sake, there are two packages that may work better. The first is MAMP which comes in two flavours: MAMP (free) and MAMP Pro (commercial). MAMP Pro contains some extra goodies if you plan on using MAMP as a production server, or need a GUI to help with configuration.

For development, MAMP is good enough. The current MAMP 1.9 includes Apache 2.0.63 (dated, but depending on your production site, this may be a closer fit if your provider uses Apache 2.0.x rather than 2.2.x), MySQL 5.1.44, PHP 5.2.13 and 5.3.2, PHP accelerators like APC and eAccelerator, phpMyAdmin, Zend Optimizer, SQLiteManager, and a number of libraries to provide extra functionality for PHP.

The other option is XAMPP, which is available for both OS X and Linux. XAMPP is completely free and version 1.7.3 includes Apache 2.2.14, MySQL 5.1.144, PHP 5.3.1, Perl 5.10.1, and ProFTPD 1.3.3 (the FTP server is one thing MAMP does not provide). It also includes a number of libraries to enhance the functionality of PHP.

Depending on your needs, XAMPP or MAMP will be a better fit; MAMP provides an older Apache but also provides support for PHP 5.2 whereas XAMPP provides the latest Apache, but only support for the latest PHP (5.3).

Both are drag-and-drop installation affairs. Simply mount the downloaded DMG and drag XAMPP (or MAMP) to the /Applications/ folder. This will overwrite the previous install -- so this is one very real drawback to these systems that you will want to keep in mind. Databases and web documents should be stored outside of the installation directory as they may get overwritten with an upgrade.

With XAMPP, once the directory is copied to /Applications/, you can easily look at the directory structure. Under XAMPP there are symbolic links for the logfile directory, the configuration file directory, and htdocs/ (the webroot). There is also a XAMPP Control GUI program that allows you to start and stop Apache, MySQL, and ProFTPd. Start Apache, provide an administrator password, and then you can use your browser to visit http://localhost/ to verify XAMPP is running.

To change the XAMPP configuration, go to /Applications/XAMPP/etc/ and edit httpd.conf. Of primary interest is the ServerRoot command near the top of the file; the default here is /Applications/XAMPP/xamppfiles/. This can be changed to point outside of the XAMPP tree to where your web site is stored.

Also keep in mind that when starting Apache and the other services, a number of files will have their ownership changed to the root user, so before upgrading XAMPP you will likely want to rename /Applications/XAMPP/ to /Applications/ and then drag the new version into /Applications/.

After that, you can move back configuration files and database files, but be sure to use something like diff on the command-line to compare the two files as they may include or remove certain features.

For a development platform, XAMPP and MAMP work quite well. Nothing beats the convenience of doing production hosting on Linux with everything laid out properly and RPM- or DEB-based packages, but for a quick and easy development platform, XAMPP and MAMP are very easy to use.