1

I need to load three virtual hosts in an exact order to make my configuration scheme work as expected.

  1. default (Apache default virtualhost)
  2. phpmyadmin (a virtualhost that serves phpMyAdmin to all pma.* subdomains)
  3. mysite.com (my website's virtualhost)

When Apache loads the default virtualhost from /etc/apache2/sites-available, it becomes 000-default in /etc/apache2/sites-enabled so it is the first (default) virtual host that Apache tries when a request is received.

Thus, I renamed my virtualhost from phpmyadmin to 00-phpmyadmin so Apache would try, in order:

000-default
00-phpmyadmin
mysite.com

To my surprise, 00-phpmyadmin comes BEFORE 000-default! See the output of apache2ctl -S:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
     default server MY_SERVER_HOSTNAME (/etc/apache2/sites-enabled/00-phpmyadmin:1)
     port 80 namevhost MY_SERVER_HOSTNAME (/etc/apache2/sites-enabled/00-phpmyadmin:1)
     port 80 namevhost MY_SERVER_HOSTNAME (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost mysite.com (/etc/apache2/sites-enabled/mysite.com:1)
Syntax OK

I had to rename 00-phpmyadmin to 0phpmyadmin to make it work as expected:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
     default server MY_SERVER_HOSTNAME (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost MY_SERVER_HOSTNAME (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost MY_SERVER_HOSTNAME (/etc/apache2/sites-enabled/0phpmyadmin:1)
     port 80 namevhost mysite.com (/etc/apache2/sites-enabled/mysite.com:1)
Syntax OK

Do you know why Apache behaves this way?

4

ASCII code for the hyphen character is 0x2d. ASCII code for the digit zero is 0x30. Hyphen comes first.

If you ever see a file listing which appears to be sorted but has 000- before 00- your locale is probably "helping" you by skipping punctuation in its string comparison routine.

  • 1
    Of course... I should have thought of this! Thank you. – GuiTeK Jul 29 '14 at 19:11

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.