Apache directory access from outside of DocumentRoot

Apache 2.2 has a document root that by default is /var/www/html. If you want to share directory not in document root, one way to do it is using the <Directory> directive. For instance I wanted to share a CentOS 6.4 install DVD which I had mounted using loop back. The way to mount an ISO file via loopback is:

mount -o loop /vm1/iso/CentOS-6.4-x86_64-minimal.iso \
/mnt/CentOS6.4/

To share the above mentioned directory via apache, in /etc/httpd/conf.d/ create a file with a .conf extension, the filename can be anything you want, in this case, let’s say the file is called local.conf. In the file place the following:

Alias /centos64 /mnt/CentOS6.4
<Directory /mnt/CentOS6.4>
Order deny,allow
 Deny from all
 Allow from .example.com
 Allow from localhost
 Allow from 1.1.1.0/255.255.255.0
 Options +Indexes
</Directory>

The ‘Alias’ part lets you access the URL with http://example.com/centos64 instead of having to type in the full directory path.
The Deny/Allow control who can access the file and the +Indexes allows directory browsing.
Now you are ready to use the URL for network installs for CentOS or whatever else you need it for!
How do you share directories via Apache? Leave your comments below.

2 thoughts on “Apache directory access from outside of DocumentRoot

  1. Tory Burch Shoes

    Hello! I’ve been following your blog for a while now and finally got the courage to go ahead and give you a shout out from Kingwood Texas! Just wanted to tell you keep up the fantastic work!

    Reply
  2. Manoranjan Barick

    Awesome. It really helps me and save my time. I was trying the same from last 2 days. But after searched lot I found your link which is a “Live Saver”. Keep it up..With your good work.

    Reply

Leave a comment