Menu Close

How to configure multiple document locations in Apache

Sometimes, you may want to use multiple locations for documents on the same website using Apache. It’s very straightforward to configure multiple document locations in Apache using the Alias directive in either the server config or VirtualHost config. Given below are the steps I used to configure a document root (/webserver/apache-2.2.12/phpMyAdmin) for the phpMyAdmin application to store it outside my default web application’s document root (/webserver/apache-2.2.12/htdocs).



STEP 1: Modify the Apache httpd.conf to add the Alias directive and ensure the new document root is accessible. Example below:

# DocumentRoot and Alias to point to pma's location outside DocumentRoot
DocumentRoot "/webserver/apache-2.2.12/htdocs"
Alias /pma /webserver/apache-2.2.12/phpMyAdmin
# Config options for pma document root
<Directory "/webserver/apache-2.2.12/phpmyadmin">
    Options -Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

Note: I explicitly configured Directory options for /webserver/apache-2.2.12/phpMyAdmin as my default Directory options (for /) were very restrictive.


STEP 2: Restart Apache. Example below:

/webserver/apache-2.2.12/bin/apachectl -k restart


Using my browser, I could access the new document root at http://xx.xx.xx.xx/pma


Points to remember:

(1) Apache permits only one DocumentRoot (understandably) for a website and so you cannot have "multiple document roots". However, you access documents stored in locations outside the DocumentRoot, thereby permitting "multiple document locations". If you have more than one domain name for your website, then you may use the VirtualHost directive to configure a DocumentRoot for each website domain.

(2) Ensure you do not add a trailing / to the url (/pma) in the Alias directive. If you do so, you will see “Not Found” errors.

(3) You should not have a directory in the document root having the same name as a URL in any of the Alias directives as you will never be able to access it. Based on the example above, if I create a directory called pma in the document root /webserver/apache-2.2.12/htdocs, then I will never be able to access any files in this directory as the Alias /pma tells Apache that it must look elsewhere (/webserver/apache-2.2.12/phpMyAdmin). However, you may create the directory pma as a subdirectory withing directories in the document root (e.g. /webserver/apache-2.2.12/htdocs/test/pma)

VN:F [1.9.22_1171]
Rating: +8 (from 20 votes)
Print Friendly, PDF & Email

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *