Configuring settings for Apache2 virtual server

In this post I will show how to configure the basic settings for apache2 based virtual server and guide a website to appear in the desired address in local computer.

Setting up Apache

sudo apt-get update I ran the update.
sudo apt-get install apache2 Installed Apache.

sudo a2enmod userdir
Enabled userdir

sudo service apache2 restart
and restarted the module.

I tested the functionality by writing "localhost" on my address bar and got "it works!"-page.


Creating a webpage

mkdir public_html
nano index.html

I created public_html on my home directory, entered and added a new folder for my virtual server ( Finally I made my index.html page with the following code:

<!doctype html>
              <meta charset="utf-8" />
               <h1>Carola's homepage</h1>
               <p>Welcome to</p>



I needed to find out my own ip address so I could get the website to appear where I wanted to. After copying it I changed the directory to hosts and modied the file by adding the ip and my own desired address.
nano hosts


Everything good so far but this wouldn't be enough. In order to work I would have to enable it from apache's settings.

cd /etc/apache2/sites-available/
sudo cp 000-default.conf

I copied my as the default-file (000-default.conf) and replaced contents with configurin server name, alias and giving the address to the root file as shown:
<VirtualHost *:80>
     DocumentRoot /home/xubuntu/public_html/

sudo a2ensite

When trying to enable my site (actually making it appear in I faced an error that claimed my site did not even exist. a2ensite is actionally a  perl script which only work with files ending with .conf. I changed my original file name from to and tried again.

sudo mv /etc/apache2/sites-available/ /etc/apache2/sites-available/

 The Result

sudo a2ensite

The second time running a2ensite was succesful and my address appeared to both and

Lectures by Tero Karvinen
Based on Linux course by Tero Karvinen (


Popular Posts