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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With