Would you like to be notified for every new articles? Please click HERE to subscribe for newsletter.

Creating Virtual Directory In Apache

  • Posted on: 22 October 2011
  • By: admin

Usually, we have to put our web application inside the document root of Apache in order to make the application accessible from the network. However, there is a trick to make the web application still accessible even though we put it outside of Apache's document root. Yes, this can be done by creating a virtual directory.

Usually, we have to put our web application inside the document root of Apache in order to make the application accessible from the network. However, there is a trick to make the web application still accessible even though we put it outside of Apache's document root. Yes, this can be done by creating a virtual directory.

Apache mod_alias

To be able to create a virtual directory, an Apache module named mod_alias must be loaded. To ensure that, we can open the httpd.conf file and look for lines like this.

LoadModule alias_module modules/mod_alias.so
 

If there is a "#" character preceeding that line, You have to delete that character first then restart your Apache.

Editing httpd.conf

If Apache mod_alias has been loaded, we can try to create the virtual directory. Open the httpd.conf, then searh the <IfModule alias_module> tag and insert some lines between it like shown below.

<IfModule alias_module>
# ADD THIS LINES FOR YOUR VIRTUAL DIRECTORIES
Alias /project1 /home/me/web/project1
Alias /project2 /home/me/web/project2
Alias /project3 /home/me/web/project3
</IfModule>
 

As you can see, the syntax for creating a virtual directory is quite simple. In the example above, we create an alias or virtual directory named /project1 and also specify its physical location , in the example its physical location is in /home/me/web/project1. We can also create more than one virtual directory using the same syntax.

The job has not finished yet. We still need to do some configuration for that virtual directory. We can do that by adding these lines.

# SETTING DIRECTORY FOR /home/me/web/project1
<Directory "/home/me/web/project1">
Options None
AllowOverride All
Order allow,deny
Allow from all
</Directory>
 

The most common configuration is like the example above. In this example we configure the directory /home/me/web/project1 used by the virtual directory /project1. If we have more than one virtual directory, we must add syntax above as many as the number of virtual directories we have.

We have to restart Apache to make the configuration changes take effect.

Comments

hi, M newbie to apache
i ve tried almost every possible way to create Virtual directory so far no success,.. m using windows Xp any suggestion ???
i ve tried your method too, .. unfortunetly it dint work out
shld i add to the lines , if so ll end up with 2 as one already exists in httpd.conf
Thanks in advance

This tutorial is for linux not for windows, i had the same problem, you have to replace the lines:
/project1 /home/me/web/project1
for the directory path you want

Thanks for sharing the code! By following these instructions I was able to create a virtual directory in Apache with ease! You can also perform this without any professional help! You should be very careful while copying the codes! A small mismatch may cause the entire program malfunction!
http://www.poweredfiles.com

Being a graduate I am in a position to suggest good platforms to my juniors fellows to get help. Among the companies I have worked with I will suggest you to hire the team working on the website http://payforessaysonline.blogspot.com/. This is a group of educated and experienced people who are really competent and providing excellent quality to their clients.

Add new comment

Limited HTML

  • Allowed HTML tags: <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.