I have just installed ubuntu (11.04).

I have installed apache/mysql/php etc.

I have a few sites sitting in


I want to be able to access these at


So in my hosts file I have   site1.local   site2.local   site3.local  

Then I have copied /etc/apache2/sites-available/default 3 times.

so now I have:


These all look like (with appropriate sitex names)

<VirtualHost site1.local>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/site1
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/site1/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128


In the terminal I then call

sudo a2ensite site1 site2 site3 && sudo /etc/init.d/apache2 reload

Which seems to work, except only one of the vhosts works at the same time (including default), What am I doing wrong?

When I run the reload command I get

  • Reloading web server config apache2
    apache2: Could not reliably determine the server's fully qualified domain name,
    using for ServerName
    [Fri Apr 15 10:45:27 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
  • @Hailwood: Are there any error messages or message output when you do sudo /etc/init.d/apache2 reload ?
    – Thomas Ward
    Apr 14, 2011 at 22:33
  • @EvilPhoenix: Check the update :)
    – Hailwood
    Apr 14, 2011 at 22:47
  • Was curious, because that matches the same error(s) I get, which explains my interest in this question you asked.
    – Thomas Ward
    Apr 14, 2011 at 22:48
  • Weird, I am surprised there is not an apache.stackexchange.com
    – Hailwood
    Apr 14, 2011 at 23:12
  • btw, just found serverfault so I have asked serverfault.com/questions/259890/… as well.
    – Hailwood
    Apr 14, 2011 at 23:20

2 Answers 2


File: /etc/hosts site1.local site2.local site3.local

File: /etc/apache2/apache2.conf

NameVirtualHost *:80

Files: /etc/apache2/sites-available/site{i}.local.conf (instead of {i} insert number: 1 or 2 or 3)

<VirtualHost *:80>
    ServerName site{i}.local
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/site{i}

In directory /etc/apache2/sites-enabled/ create symbolic links:


Restart apache and have fun :)

  • 2
    One note is that the line suggested for /etc/apache2/apache2.conf was found in /etc/apache2/ports.conf which is imported by apache2.conf
    – Hailwood
    Apr 18, 2011 at 23:51

There is a script that makes this simple for you - https://github.com/RoverWire/virtualhost

This eventually does the same thins as explained by the answers given but does it in just one command eg. -

sudo virtualhost create mysite.local my_site

It also allows you to delete a host you created

sudo virtualhost delete mysite.local my_site

Just note that the "my_dir" assumes that it starts after /var/www

So if your site folder is in /var/www/my_site

You should run this (pass directory path without /var/www) -

sudo virtualhost create mysite.local my_site

You can also modify the script file & remove the default path "/var/www" so that you can pass an absolute path to the site directory

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .