Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create more than one document root in apache2

I would like to create a virtual host in apache2, but I want it to place the source files outside the /var/www folder, i.e. I need to include another document root in the config files, but I implemented it by editing the apache/sites-available/default file, but I know its not the right way to implement, can any one suggest the correct way of implementing it?

with thank and regards,

bala

like image 340
Bala Varadarajan Avatar asked Apr 25 '11 07:04

Bala Varadarajan


People also ask

What is the document root of apache2?

On Ubuntu, the Apache web server serves documents stored in the var/www/html directory by default. This directory is referred to as the document root.


1 Answers

You can create a new file (e.g. myvirtualhost) in the sites-available folder and then create a symlink in the sites-enabled. The file and the symlink can have any name.

Inside the new file you create a new virtual host definition:

<VirtualHost *:80>
    DocumentRoot /path/to/your/webapplication
    ServerName abc.local
</VirtualHost>

If you are deploying your application only locally for testing it is enough to set the server name to a .local domain (e.g abc.local) in this case you should edit the /etc/hosts file and add a new line like.

127.0.0.1 abc.local

If you want to make the new virtual host available on the internet you need to make sure that you have registered a valid DNS name with your provider (e.g. webapplication.mydomain.com).

Basically thats it. You may however want to add some directives to the virtual host definition to control access to your resources.

like image 137
lanoxx Avatar answered Oct 08 '22 19:10

lanoxx