I'm new to Linux world and I'm getting stuck with the Apache version 2.2 Virtual host configuration.

In my local /var/www I have 2 sites (and the default localhost) in their respective directories:


Importer is an importer for a Opencart installed into daxstore directory, which I'm developing. I want two distinct sites working so I've copied the file


into the same directory two times, renaming it into "importer" and "foostore" and then edited them to:

<VirtualHost importer:80>
ServerAdmin webmaster@localhost

ServerName  importer
DocumentRoot /var/www/importer/
<Directory />
    Options FollowSymLinks
    AllowOverride None
<Directory /var/www/importer>
    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 debug
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

switching the name for the other side. I then edited /etc/hosts as follows:   localhost   VirtualHD   foostore   importer

Then I give the commands:

sudo a2ensite importer
sudo a2ensite foostore
sudo service apache2 restart

and apache goes right. When I try to access both sites, the browser redirect me on the foostore site (which also can't find some files but this is a matter for another question). Where am I wrong?

Thank you sirs.


Change the <VirtualHost> blocks of both site configurations from <VirtualHost importer:80> to <VirtualHost *:80> and make sure you have the correct ServerName directive in each file. Reload Apache.

If that doesn't help, check both access.log and error.log to get information about what Apache is actually doing.


First, make sure you have a NameVirtualHost *:80 line in your /etc/apache2/ports.conf file. Then try changing <VirtualHost importer:80> to <VirtualHost *:80> in your config.

  • obviously it is listening on port 80 if one of the sites loads – Christian Oct 13 '12 at 12:48
  • 1
    Right, that's the Listen directive's job. But if there's no NameVirtualHost directive, then name-based virtual hosts will not work properly. – Brian Showalter Oct 13 '12 at 20:15

First disable both the sites you just added using a2dissite site

Open up the default file and add the following to the top. Nice and simple. If you want to move them into their own conf file later or change security, you are welcome but test this first.

<VirtualHost *:80>
  ServerName importer
  DocumentRoot /var/www/importer

<VirtualHost *:80>
  ServerName foostore
  DocumentRoot /var/www/foostore

Then restart apache service apache2 restart

  • I can't add those section into the default site. It says: <VirtualHost> cannot occur within <VirtualHost> section Action 'configtest' failed. The Apache error log may have more information. Maybe I've misunderstood what you trying to tell me. – IssamTP Oct 14 '12 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.