Dave's picture

Hey Guys,


We are using turnkey linux magento with turnkey HUB backup ( awesome and low pricing so highly recommended :).

Now we want to setup Vhosts on our server, i will give as much info as i can and think of right now.I am breaking my head on this now for over a week and just can't get it to work...

I tried everything i can find on the internet, problem is that on our server is used Apache 2.2.22 and most people have either older versions of Apache or newer, so it never fits on what i can read.

Because this version does not seem to work with a Httpd.conf file and there is this file etc/apache2/sites-enabled/000-default wich seems to be empty.

Now if i use webmin and add use ''Create virtual host'' and fill everything with what is needed stated on apache website.

Either only the first website that is on the server will listen to both URL's we have OR i get it to work to only have the second website listen to both urls.

So either one of two websites is available with both urls.

www.website1.be ans www.website2.com

maybe also good to know, we have a dedicated Ip adres for the server, both url's we have point to this ip adress.

Server is behind a router that is connected to the modem wich has the dedicated IP.

I know for sure i am doing something wrong, or forget to do something elsewhere but just can't put my finger on it.

I know you guys will need more info, so will give it to you upon request.

Highly appreciated if someone wants to dig in to this.


Jeremy Davis's picture

The most important thing to realise when you do Apache config is that Debian (and derivatives inc Ubuntu etc) configure things a little different to the default Apache way (which is what RedHat/CentOS/etc use).

By default (Apache upstream & RedHat et al) Apache has a (massive) monolithic config file often called httpd.conf. In Debian (and derivs) that monolithic file is broken down and split into different sections, with each section contained in a different conf file.

So to change or add a port for Apache to listen on; instead of looking for the ports declaration in /etc/httpd/conf/httpd.conf (RedHat et al) you just edit /etc/apache2/ports.conf. Instead of adding a new virtualhost to your monolithic httpd.conf; you add a new site file (containing your vhost info) to /etc/apache2/sites-available. You then enable it with 'a2ensite site-name'. FWIW the a2ensite command simply creates a symlink from /etc/apache2/sites-available/site.conf to /etc/apache2/sites-enabled/site.conf
Note as of Apache2.4 (not the version you are using; the next one that is in Debian Jessie and will be in TKL v14.0) the vhost (sites) file must have a .conf file extension. So even though it's not required for the version you are working with it's probably a good habit to get into now...

Personally I have had limited success with the Webmin module although TBH I didn't try very hard... Once you get your head around the differences between Apache implementations and only read the right info (i.e. as a TKL user read stuff that explicitly relates to Debian/Ubuntu) then it isn't that hard to set up...

So IMO the first step is to do some reading about Apache config in Debian Wheezy (aka Debian 7). That should get you headed in the right direction. Then adjust the existing enabled site (have a peek in /etc/apache2/sites-enabled/ to see what's enabled already). Also I recommend that you create a local backup of any files that you edit so you can easily roll back changes if they don't work. So here's how I'd start:

# ls /etc/apache2/sites-enabled/
magento phpmyadmin

# cp /etc/apache2/sites-available/magento /etc/apache2/sites-available/magento.backup
# nano /etc/apache2/sites-available/magento

Then go crazy editing and changing things around until it works how you want. Remember that Apache needs to be restarted before changes are applied (service apache2 restart). Personally I'd be inclined to make a separate site file (in /etc/apache2/sites-available/; enabled with a2emsite) for your new domain (so they are somewhat independent of one another).

I'm sorry that I'm probably light on specifics but hopefully that will get you going in the right direction. Have a little read and a play and please please post back. If you've worked it all out then share your victory and what managed to get it working for you. Or if you still can't get it then hopefully someone (probably me) will try to help you further...

Dave's picture

Hey Jeremy,

Thank you very much for your time and help.

Seems that i have been doing things right, i used A2ensite and A2dissite.
I also see the links in the the map ''sites-enabled''.

But most of the time it's just the first installed website in the main root folder that will be seen with both URL's.

Strange thing that i can't get figured out is the 000-default map.
It is blanco, but if i put code in it, from what i found on the internet, the webiste goes down.
So my guess is that i need to put something in there that is crucial for getting things to work ?

Or am i totally wrong.


For sure i will search further, but i am missing something crucial here and i just can't get it figured out.

But if i do, i surely will share it here!!!

In the mean time, if just anybody had this figured out allready, pleasse share :)

Thanks in advance!

Jeremy Davis's picture

I don't know for sure but I image that the main thing missing is that all your virtual hosts are just using wildcards (i.e. asterisks; '*').

So instead of:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
You will need something like:
<VirtualHost www.website1.be:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/website1
<VirtualHost www.website2.be:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/website2
Then www.website1.be should display /var/www/website1/index.php and www.website2.be should display /var/www/website2/index.php

As I said I would recommend putting them in separate site files. E.g. /etc/apache2/sites-available/website1 & /etc/apache2/sites-available/website2 and then enabling them with a2ensite website1 & a2ensite website2.

If you do this as root (which you probably are), then you may need to change the file permissions. The easiest (although not the most secure) way is to make www-data (the webserver user account) own all the while directory tree:

chown -R www-data:www-data /var/www/

Also don't forget to restart Apache after any config changes.

Dave's picture

Tried it, but this is what i get:

Starting web server: apache2[Tue Aug 04 23:17:18 2015] [warn] VirtualHost www.website1.be:80 overlaps with VirtualHost www.website2.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Tue Aug 04 23:17:18 2015] [warn] _default_ VirtualHost overlap on port 12322, the first has precedence
Jeremy Davis's picture

TBH I haven't ever configured an Apache website with multiple named virtualhosts. I shouldn't have relied on my memory to answer your question and should have either said I wasn't sure and/or actually checked...

So this time I actually looked it up. Have a look here. To make life easier; I have translated that to what you'll need to do for your scenario:

<VirtualHost *:80>
        DocumentRoot /var/www/website1
        ServerName www.website1.be

        # Other directives here

<VirtualHost *:80>
        DocumentRoot /var/www/website2
        ServerName www.website2.be

        # Other directives here

As noted in the docs you could swap out the asterisk for the actual IP address (not the name! Doh!) but it's not required...

Apologies on the confusion and misdirection...

Dave's picture

Hey Jeremy,

Also tried that, i think i allready did that.

I can for sure say i tried everything, found on the internet.
For me it is impossible to find out what causes it not to work.

Or the website that i put in the /var/www   root folder shows always up, even if i use the second URL.

Or i get the other website under both url's, but seperate is impossible.

Do you know if i have to do something in the /etc/hosts file ?

Thanks for you time !


Jeremy Davis's picture

Well sorry that I have been of no use to you at all! :(

I'll have to sit down and have a play and see if I can get it working. Unfortunately ATM I'm flat out trying to get the v14.0 release out the door, so please excuse my lack of further help...

The things that occur to me (OTTOMH) are:

  • not restarting apache
    • make sure you restart apache everytime you change config
      service apache2 restart
  • some unknown/unintended conf somewhere else also being loaded
    • check for occurences of the default path (/var/www) everywhere in the apache conf directory (/etc/apache2) with grep:
      grep -r /var/www /etc/apache2
    • Note you can ignore anything that occurs in sites-avaialble; but isn't symlinked in sites-enabled
  • your system/browser/etc caching things
    • try using incognito/private mode and/or use an additional browser
Dave's picture


First of all , your support is highly appreciated !

So if it works or not, that does not matter !!!

I am happy i have someone who wants to think with me, so any input is highly appreciated.
I share a virtual beer with you ;)

I know apache needs to be restarted with every setting that is used, it is one of the things people keep hammering on when giving support.

Maybe i am the biggest factor of not getting it done, for sure i am not a linux guru !

Despite that i really used all that i could find at many many many threads resulting almost every time with ''yeajjjj it works, or thank you so much this worked for me'' from all kinds of readers of that post.
Only those answers seem not to be the fix for my version of apache / webmin.

The stupid thing is, i can delete every vhost , also of the website that is in the main root folder : /var/www
The damn website keeps working.

Even if there is no VHOST, so somewere there must be a ''default'' setting ???

It seems the main website is this vhost/etc/apache2/sites-enabled/magento

If i empty the conf file ''magento'' the website still works, do i even put one word in it press save and restart apache then the website get's unreachable.


So why is it possible to delete that config file, and still have a working website, is that because there is always a default that says, send every url from the ip adress to the /var/www folder ?


Now, last thing i have done is this:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.mywebsite.be
ServerAlias mywebsite.be *.website.be
DocumentRoot /var/www

<VirtualHost *:80>
ServerName www.otherdomain.com
DocumentRoot /var/vhosts/magento

After saving and restarting i get this warning:

Failed to start apache :

Starting web server: apache2[Sat Aug 08 17:11:59 2015] [warn] _default_ VirtualHost overlap on port 12322, the first has precedence
Jeremy Davis's picture

So it seems to me that you have multiple configs enabled somewhere along the line... IMO first thing to check is what is in /etc/apache2/sites-enabled/ i.e.
ls -l /etc/apache2/sites-enabled/

By default there should be 2 symlinks; one to /etc/apache2/sites-avaialble/magento and the other to /etc/apache2/sites-avaialble/phpmyadmin If you have any more than that that is possibly your issue... Feel free to post the result of the above command if you want my input...

Also I only just noticed; in your error message:

...default_ VirtualHost overlap on port 12322...
That is the port that PHPMyAdmin is served on by default. If you have an overlap on that then there it must be defined in multiple places.

Please post back the result to this:

grep -r 12322 /etc/apache2
Also make sure that Apache has read permissions to your Magento site (/var/vhosts/magento); although I assume that it does (as you say that bit works).

Also perhaps it is worth downloading a clean appliance; boot it up in VirtualBox (or similar); edit your hosts file (on the host system) to point ot your VM (with 2 different test server names). Then muck around with that until it works... Then once you have a known good config you can try transferring it back to your current system...

Dave's picture

root@magento ~# ls -l /etc/apache2/sites-enabled/
total 4
-rw-r--r-- 1 root root 0 Jul 28 14:50 000-default
-rw-r--r-- 1 root root 886 Aug 10 00:13 magento
lrwxrwxrwx 1 root root 29 Oct 15 2013 phpmyadmin -> ../sites-available/phpmyadmin
root@magento ~# grep -r 12322 /etc/apache2
/etc/apache2/ports.conf:Listen *:12322
You have new mail in /var/mail/root
root@magento ~#

Jeremy Davis's picture

I'm sort of surprised that port 12322 didn't show up more than once. It seems clear (from your error message) that it is being defined twice. So is your additional site info in 000-default? If not perhaps it would help if you disabled that...
a2dissite 000-default
Then try starting pache again. I'd also look at the apache error log too (that might have some useful info). FYI that should be /var/log/apache2/error.log

Also looks like you have mail (probably error info). Read it like this:

cat /var/mail/root
and when you want to get rid of it:
rm /var/mail/root
Dave's picture

Hey Jeremy,

As you posted, i build a new server setup with parts that ia had laying around.

Installed exact same software distro.
I could setup the vhost's in a heartbeat, really just in a few minutes i had it working.
I read so much tutorials that the setup was a piece of cake.

So that raised the question, why in the world does that not work for the live server.

So I opened all config files side by side and took over all that was different.

It worked, unfortunately i can't say what was the faulty thing, as there were a lot things different.
But all in a same kind of way.

Like: Listen *:12321

insted of Listen 12321
So in the ports.conf file it looks like this now:

#Listen *:12322
#Listen *:12325
#Listen *:12326
Listen 12322


And also in the vhosts file i had some of these that should not be there (  ''  )

Like : DocumentRoot ''/var/www/''

instead of DocumentRoot /var/www/

Also copied the hosts file in /etc   as there also was something others configered.


Only i still have this thing to work out:

Starting web server: apache2[Wed Aug 12 11:30:21 2015] [warn] _default_ VirtualHost overlap on port 12322, the first has precedence


I do not know why, but now it works.

Thanks for sharing your thoughts with me.


Jeremy Davis's picture

Perhaps it might be worth doing a TKLBAM backup of your existing site and then restore to your test server; but excluding /etc/apache2 (see the TKLBAM docs; specifically tklbam-restore; I suggest using the '-simulate' switch to check that it will do what you want first...).

Also FWIW using virtualisation is a very handy way to test stuff. Essentially you can do what you did on you old hardware but it's much easier to work with and worst case to can trash it and start again quite easily... VirtualBox is easy to use, cross platform and free!

Add new comment