Tutorial: reconfiguring virtual hosts after upgrading to Apache 2.4.7 on Ubuntu – what you need to change


Once upon a time, I was running Apache 2.2.22. I had set up my virtual hosts by making up some fantasy domain names for each of my sites, such as drupal.kevin. I would then edit /etc/apache2/vhosts.conf to add information about my DocumentRoot, DirectoryIndex and CustomLog for each of my sites. Because I wanted to make sure they were always backed up properly, I kept my websites in my /home folder rather than /var/www/html, which meant I also needed a symlink from there to my websites directory. Lastly, I would add a line for every virtual host in /etc/hosts, such as drupal.kevin

So far so good. Unfortunately, all that stopped working after upgrading from Ubuntu 12.04 LTS (Precise Pangolin) to 14.04 LTS (Trusty Tahr)…

Hopefully the following will save you from spending hours figuring out how to get your virtual hosts back. I’m going to work on the assumption that you had Apache and PHP set up on your previous Ubuntu and used the upgrade instructions, rather than doing a fresh installation. Ubuntu 14.04 will by default attempt to reinstate most of your applications from 12.04, including your webserver.

1 – setting up symlinks

link to custom htdocs folder

If – like me – you keep your website folders in /home, you will first of all need to create a symbolic link. I want to bypass /var/www/html, otherwise I end up with too much directory depth.

$ sudo ln -s /var/www/ /home/[your_username]/[path_to_website_folder]

setting up phpMyAdmin

If you had phpMyAdmin installed, you also need to make sure there is a symbolic link in your websites folder, so that you can access your databases via a browser (otherwise you will see nothing when you go to http://localhost/phpmyadmin/):

sudo ln -s /usr/share/phpmyadmin /home/[your_username]/websites

2 – the VirtualHost config files


Start by editing the default configuration file at /etc/apache2/sites-available/000-default.conf
it should look similar to this – make sure the paths given in the <VirtualHost> and <Directory> directives correspond to your own htdocs folder:

sample contents of 000-default.conf

sample contents of 000-default.conf

custom virtual hosts configuration

If you have many different virtual hosts like I do, you must add a config file for each of your hosts. The minimum to put into the <VirtualHost> directive is your domain and the path to the htdocs folder you pointing to, which is replicated further down in <Directory> – here an example of my drupal.kevin config file, which is at /etc/apache2/sites-available/drupal.conf:

custom virtual host config file

sample configuration for one of the virtual hosts


As you are planning to use virtual hosts rather than localhost, go into  /etc/hosts and comment out the existing lines with a hash:

# localhost
# [name-of-your-computer]

otherwise, you will get an ‘AH00558: apache2: Could not reliably determine the server’s fully qualified domain name‘ error message
Then add your virtual hosts below what you’ve just commented out. This is an example of the fantasy domains I am using, which you will replace with [name_of_virtual_host]: drupal.kevin ushahidi.kevin wordpress.kevin 

finishing the configuration

Once you’re done, don’t forget to tell Apache about your virtual hosts by doing:

$ sudo a2ensite [name_of_virtual_host]

which will create a symlink from /etc/apache2/sites-available to /etc/apache2/sites-enabled. You need to do this for every virtual host you have created. Restart Apache to let the changes take effect.

$ sudo service apache2 restart

Now everything should work perfectly!

3 – still need some troubleshooting?

Drupal issues

My standard hand-coded PHP sites were fine, but there seemed to be something wrong with my Drupal sites. The front page displayed ok but when I went into the Drupal configuration menu I got an ‘/admin/config not found‘ message in the browser. This was fixed by also adding AllowOverride All in every single one of your custom virtual host config files, so make sure you have done this as per the instructions above.

check your dynamic links

So now that all my recent sites worked, including those using a CMS – one of my older ‘hand-coded’ sites wasn’t seeing any CSS from a subdirectory that was higher up: I was on the landing page of mosaic.kevin/training but it wasn’t picking up mosaic.kevin/css/mosaic.css
On top of this, my navigation links all had the wrong path. The culprit turned out to be some links that were not dynamic. So the moral of the story is: validate your html properly, especially on sites that haven’t had a makeover for a while!


<...href='../photos/pride-2003_1.jpg'> or <...href='photos/pride-2003_1.jpg'>



remember your forward slash, without anything else in front.

3 thoughts on “Tutorial: reconfiguring virtual hosts after upgrading to Apache 2.4.7 on Ubuntu – what you need to change

Leave a Reply to wluqmanws Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.