Snow Leopard Development Server: Apache 2

Next up is the web server. Apache 2 comes pre-installed on Leopard systems (Mac OS X 10.5 and 10.6), but I want all my open source projects to work alongside one another.

Apache 2 Install

As always, update MacPorts itself before proceeding with any installation.

sudo port -d selfupdate
sudo port install apache2
sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

The last command ensures that Apache 2 will launch at startup.

Apache Configuration

With Apache 2 installed, my next task is to configure it. To create an initial configuration file, I copy a sample distributed with the MacPorts Apache 2 installation. Note: This step is not always necessary: It appears that the latest Apache 2 installations simply create a default httpd.conf.

sudo cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf

Since one version of Apache 2 already runs courtesy of Leopard, I need to make some modifications to the configuration file for the MacPorts installation. In particular, this version will operate on port 8080 instead of the standard port 80.

sudo vi /opt/local/apache2/conf/httpd.conf

I made the following changes to /opt/local/apache2/conf/httpd.conf.

Listen *:8080
NameVirtualHost *:8080

ServerAdmin markf@istarelworkshop.com
ServerName 127.0.0.1

<Directory "/Users/markf/Sites">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

# At very bottom of httpd.conf
Include /Users/markf/Sites/httpd.conf

DocumentRoot

I use the /Users/markf/Sites/httpd.conf configuration file to set the DocumentRoot and other key attributes.

Listing: /Users/markf/Sites/httpd.conf

<VirtualHost *:8080>
    ServerName dev.minethlos.com
    DocumentRoot /Users/markf/Sites/

    AcceptPathInfo On
    UseCanonicalName Off
    DirectoryIndex index.php index.html

    <Directory /Users/markf/Sites/>
        Allow from All
    </Directory>
</VirtualHost>

With Apache2 and PostgreSQL installed, I am now ready to complete the initial setup with PHP 5.