Reputation: 514
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
Upvotes: 10
Views: 17898
Reputation: 1
I just want to add to the already existing answers. You don't strictly need to edit the hosts file on your system. You can just use another local ip , ie instead of using 127.0.0.1 you can use 127.0.0.2. in fact it can be any ip that starts with 127
Your virtual hsot definition will then be like this:
<VirtualHost 127.0.0.2:80>
DocumentRoot /path/to/your/webapplication
ServerName 127.0.0.2
</VirtualHost>
Upvotes: 0
Reputation: 3325
you can go to your httpd.conf file (apache config file located in conf directory). Then find a line which reads:
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
then uncomment the second line like this:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
go to your "extra" folder also located in the conf foler. You will see file named "httpd-vhosts.conf"
Edit the file in the virtual host samples:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "...full path to you new root folder for this site...."
ServerName yourwebsite.com
ServerAlias www.yourwebsite.com
ErrorLog "logs/newpath.error.log"
CustomLog "logs/newpath.access.log" common
</VirtualHost>
but this is very simplified solution, please read more on virtual hosts, but it should point you to the right direction
Upvotes: 1
Reputation: 13051
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.
Upvotes: 8