Apache Cheat Sheet

This page is a list of tips for the Apache Web Server version 2.

Create a Virtual Directory

An Apache virtual directory adds a directory to you Apache server that is outside of your server root. This can be useful when you are hosting multiple websites, or just need to add some test directories to the server without changing the document root. To create virtual server, a directory entry needs to be reated and an alias.

Set up the directory rights and permissions like this.

<Directory "/dir/subdir/dojo">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
	

And the alias like so.

<IfModule alias_module>
Alias /dojo /dir/subdir/dojo
</IfModule>
	

Note that the directory entry and the alias must point to the same directory. Your alias should be in the IfModule block to make sure that module is installed. Now accessing the server via http://localhost/dojo will display the contents of the dojo directory.

Hosting Multiple Sites on Separate Ports

Below are the changes that need to be made to httpd.conf to setup two virtual hosts. One on port 80 and one on port 81.

# Lines that follow setup two virtual hosts on this machine
# The following lines tell the Apache Server to listen on more than one port
Listen 80

Listen 81


# The VirtualHost statements setup two document roots on different ports
<VirtualHost 127.0.0.1:80>

	ServerAdmin temp@temp.com
	DocumentRoot "c:/dir1"
	ServerName www.host1.com
</VirtualHost>


<VirtualHost 127.0.0.1:81>
	ServerAdmin temp@temp.com
	DocumentRoot "c:/dir"
	ServerName www.host2.com
</VirtualHost>
	

The Listen statements are needed to tell Apache to accept requests on those ports. The VirtualHost statement defines the location of the document root, links the host to one of the ports being listened to, and defines a host name for that port.

Operating System Specifics

OS X

Directory Locations

Document Directory /Library/Webserver/Documents
CGI-BIN Directory /Library/Webserver/CGI-Executables
Configuration Files (Pre-Leopard) /etc/httpd/httpd.conf
Configuration Files (Leopard) /etc/apache2/httpd.conf
Default Log Files (Pre-Leopard) /private/var/log/httpd (both error and access logs can be found here.
Default Log Files (Leopard) /private/var/log/apache2 (both error and access logs can be found here.