I'm configuring an apache server to support a few virtual hosts with different subdomains. Situation:

Right now, there are 4 subdomains pointing to same IP:


List will be extended later with other names. First one, should load default vhost with something like Welcome page. Second one used in vhost serving svn repos, third one a webmail client and last one phpmyadmin.

Next, i have 4 sites enabled:

000-default.conf -> ../sites-available/000-default.conf
010-svn.conf -> ../sites-available/010-svn.conf
020-roundcube.conf -> ../sites-available/020-roundcube.conf
090-phpmyadmin.conf -> ../sites-available/090-phpmyadmin.conf

First one is a default apache2 config:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

Second, svn repos host configuration:

  ServerName svn.example.com
  <Location />
    ... SVN stuff ...
  ... SSL stuff ...

Webmail vhost:

<VirtualHost *:443>
  ServerName mail.example.com
  DocumentRoot /home/webapps/roundcubemail-1.1.2

  ... SSL stuff ...

  <Directory "/home/webapps/roundcubemail-1.1.2">
    Order allow,deny
    Allow from all
    Require all granted

<VirtualHost *:80>
  ServerName mail.example.com
  Redirect / https://mail.example.com/

And phpmyadmin:

  ServerName mysql.example.com
  DocumentRoot /usr/share/phpmyadmin
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  LogLevel notice
  CustomLog /var/log/apache2/access.log combined
  ErrorLog /var/log/apache2/error.log
  ServerSignature On 

So, again, its supposed to:

http://srv.example.com => land on 'default' vhost (000-def...)
http://svn.example.com => land on 'default' as SVN is served on 38443 port
http://svn.example.com:38443 => land on svn vhost
http://mail.example.com => redirect to https://mail.example.com
https://mail.example.com => land on webmail vhost
http://mysql.example.com => land on phpmyadmin vhost

But, its no working like this:

http://srv.example.com => loads phpmyadmin vhost
http://svn.example.com => loads phpmyadmin vhost too
http://svn.example.com:38443 => lands on svn vhost
http://mail.example.com => loads phpmyadmin vhost
https://mail.example.com => land on webmail vhost
http://mysql.example.com => land on phpmyadmin vhost

So, generally, apache2 is taking last vhost (mysql) as default one. And for some reason mail redirect is not working.

I have no idea whats wrong, as i googled some, it should work, when subdomain doesn't fit to any of defined vhosts, it should load first one (000-default as from order of symlinks) - so why it loads last one?

Edit 11.09.2015

Problem seems to be in phpmyadmin configuration, when i disable its vhost, everything works as expected, and when i enable it again its bad again.

Dont know why this happens...

4 Answers 4


If you don't have a servername in the default vhost, you will just get a warning that apache can not reliably determine the hostname on every Apache restart or reload.

Did you restart or rload Apache after changing the config ?

Does the server actually run on and how did you assign that ip-number to the hostnames when testing?

Are you using the /etc/hosts file for that purpose?

Make sure that instead of a hosts file line: srv.example.com svn.example.com mysql.example.com

You have: srv.example.com svn.example.com mysql.example.com

Or change the vhost from to *:80

  • Server machine has 3 network interfaces and subnet is on one of them. Both 'internal' networks are configured statically, 3rd one is dynamic. And yes, subdomains are defined in /etc/hosts by the second way you described and then distributed to all other LAN clients by dhcp, so all machines ale properly resolving all subdomains.
    – WombaT
    Sep 11, 2015 at 11:28

Well, after a lot of blind shot tests im still not sure what was exactly the problem, but i got it working as i desired by changing phpmyadmin configuration to not bind to specific interface but to all.

Now i have <VirtualHost *:80> instead of <VirtualHost>. That change "fixed" apache behavior in picking up right virtual hosts but resulted in a availability of phpmyadmin on all subnets - not so good.

Then i thought that binding vhost to only one subnet to prevent users from other subnets from accessing it wasnt best idea and maybe it would be better to set properly apache permissions? With that in mind after a few minutes a got added this to vhost conf:

<Directory "/www/webapps/adminer">
    Require ip

(and yes, in the meantime i switched phpmyadmin to adminer)

And now everything works as expected. Only one thing that im thinking about now is that maybe it would be better for users to see theres no such thing (404) instead of there is something, but you cannot access it (forbidden) but its a topic for another question i guess....


Couple of things jump out at me:

Is it supposed to be <VirtualHost> ?

Not <VirtualHost *:38443> ?

and there's no ServerName in your default either. I tend to generally have one.

----- EDIT -----

If you are trying to restrict who can see the site then you would need to set up rules about that INSIDE the VirtualHost declaration:

<Location />
    Order Allow,Deny
    Allow from
  • I agree with the ServerName and think that's probably the issue. The IP address is valid in the VirtualHost statement to listen only on a specific interface (and it's one of his servers that was originally working) Sep 10, 2015 at 22:47
  • @Andrew Myers: yes, its supposed to be with certain IP address as that vhost should be accessible only on this subnet.
    – WombaT
    Sep 11, 2015 at 11:25
  • @WombaT Please see my recent edit. Oct 5, 2015 at 12:16

I've observed the misbehavior mentioned in the original question: as soon as I enabled the PhpMyAdmin VirtualHost, it would override (hijack) my default VirtualHost.

The default VirtualHost is normally inferred from the order of the VirtualHost entries in Apache's config. The first VirtualHost becomes the default. That's why in the multi-file config, where apache.conf just includes all the site.conf files, the default VirtualHost's filename is often called 000-default or something like that.

In my case, originally I had all the VirtualHost entries declared as

<VirtualHost *:80>
     ServerName ...

and the default VirtualHost would get inferred just fine. After adding a VirtualHost for PhpMyAdmin, it would become the default.

And, contrary to the accepted solution, I had to rework the VirtualHost declarations to include a particular IP address. Which is where the "first VirtualHost to occur in config" took over again. I had to declare them all with an IP address : the default VirtualHost, the PhpMyAdmin VirtualHost, and all the other VirtualHosts that I have.

Apache httpd version: 2.4.10-10+deb8u16

Seems as if mod_php loads as a global extension to httpd and gets precedence over the standard "selection of default" on part of stock httpd...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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