How to configure a virtual host using Apache at Ubuntu
Hi all, this is a simply “how to do” post named “How to configure a virtual host using Apache at Ubuntu”, I’d like to share.
At first, we need to have the apache environment at our server (in this case I am using my own machine for this: “localhost“). So using the terminal, we type the following line command:
sudo apt-get install apache2
After this, we can go to the web browser “http://localhost” and if it shows something like “It works”, it means apache has been successfully installed at your machine.
Okay so now let’s start configuring our virtual host. Using the terminal, edit the file default located at “/etc/apache2/sites-available/default”.
sudo gedit /etc/apache2/sites-available/default
Please pay close attention on the picture bellow, actually at the red and blue parts, the picture shows the code you need to insert into the default file you just opened. Here goes some information:
- VirtualHost, indicates there will be a new virtual host and it will accept everything from port 80.
- DocumentRoot, indicates where your site folder is located inside the apache server, in this case there’s a folder named “drupal” inside /var/www/.
- SeverName, indicates the url the apache will use to go into the folder drupal.
- Directory, again indicates the path for the folder drupal inside the server, also there, you can add some options such as “AllowOverride” or “Options”.
Now you’ll need to edit another file located at /etc/ folder named “hosts”:
sudo gedit /etc/hosts
At this file you’ll need to add the following code:
127.0.0.1 drupal drupal.localhost drupal
At this code you are including drupal.localhost as a new host for apache.
Finally, you’ll need to restart apache environment and test if the new virtual host is working typing “http://drupal.localhost”:
sudo /etc/init.d/apache2 restart

