Fork me on GitHub

Apache2 Virtual Hosts

Hey guys,
we’re going to add a new virtual host in apache2

1) create a new virtual host file in /etc/apache2/sites-available

Code:
$ cd /etc/apache2/sites-available$ touch newhost

2) use your favourite editor to put what follows in that file. Change the document root to wherever you want to put your host. Change the server name to the address where you want to access your host:

Code:
<VirtualHost *>   ServerName rails   DocumentRoot /var/www/newhost/

   <Directory /var/www/newhost/>

       AllowOverride all       Order allow,deny       Allow from all

   </Directory></VirtualHost>

3) having set up this file, we then need to symlink to it from the sites-enabled directory. Let’s do that now:

Code:
$ cd /etc/apache2/sites-enabled$ ln -s ../sites-available/newhost newhost

4) In order to get the apache2 server to display this site when you access it, you’ve got to add this ServerName alias next to 127.0.0.1 in your /etc/hosts file, or your web browser is _not_ going to know where to go when you give it in your address bar. Here’s the beginning of mine:

Code:
127.0.0.1 newhost etc...

5) Now we’re pretty well done (so long as I haven’t left a step out). Restart your apache2 with:

Code:
$ /etc/init.d/apache2 restart

see you next,
Antonio

ps. Thanks to Siennalizard

No comments yet.


Leave a comment

(required)

(required)