Setting up the VirtualHost Configuration File

We start this step by going into the configuration files directory:

cd /etc/apache2/sites-available/

Since Apache came with a default VirtualHost file, let’s use that as a base. (gci.conf is used here to match our subdomain name):

sudo cp 000-default.conf gci.conf

Now edit the configuration file:

sudo nano gci.conf

We should have our email in ServerAdmin so users can reach you in case Apache experiences any error:


We also want the DocumentRoot directive to point to the directory our site files are hosted on:

DocumentRoot /var/www/gci/

The default file doesn’t come with a ServerName directive so we’ll have to add and define it by adding this line below the last directive:


This ensures people reach the right site instead of the default one when they type in

Now that we’re done configuring our site, let’s save and activate it in the next step!


After setting up our website, we need to activate the virtual hosts configuration file to enable it. We do that by running the following command in the configuration file directory:

sudo a2ensite gci.conf

You should see the following output

Enabling site gci.
To activate the new configuration, you need to run:
  service apache2 reload

After activating your site you need to edit your hosts file

The easiest way (most GUI) would be to use gedit. You could also use any other editor you prefer (e.g. nano or vi). Just run the editor as root using sudo and you’re good to go! You need to pass 1 argument: the path to the file you want to edit (in this case /etc/hosts).

The full command:

sudo -i gedit /etc/hosts

To load the new site, we restart Apache by typing:

service apache2 reload

For  index.php file hiding  needs to put this

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2’s
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/


Leave a Reply