A nice clean way to run lots of web sites on your Magento App Server is to configure each domain with its own httpd style config file, I keep mine in /etc/httpd/vhosts.d and each domain has its own file carefully named so the Apache httpd.conf script can read the SSL sites separately to the HTTP sites and any site specific config is in the file for the site and not polluting the main httpd config file which remains almost vanilla, making upgrades and backup very easy.
Update Jan 2013
I have been asked why this is a good idea and my thinking behind some of the sys admin stuff I implement – so here are some thoughts:
- Upgrades – I like to build a CENTOS OS in the bare minimal state using PXE boot off the network, with over 2000+ VM’s and Containers to manage and the need to spin-up stuff often, a clean, minimal install is always best using YUM to install packages as needed, if its not a package it does not get installed. No hand building and it can be scripted so recovery can be quick!
- Minimal config, while changing httpd.conf seams logical, when you try to manage a 1000 domain config file – forget it… 1 error and nothing works. If I need to disable a site, I rename its config to .disabled… and reload httpd, no issues and no fuss.
- Easy backup and recovery. with just a few minimal config changes in the httpd.conf file, I can use rsync to backup my domain config directory everyday to a backup server.
- Less OS footprint – I don’t like embedding lots of files into the OS, I prefer to have a /logs directory and a /data directory for my application logging and data and to not tie to the OS directory structure too deeply. New OS build and just create and copy back the directories…. easy!
- The default httpd document root starts at /var/www so a minimal out of the box install requires no changes and I can rsync /var/www to another server daily to maintain an exact snapshot of my web sites be it static or dynamic.
Directory and File Details
If I do an “ls” of my /etc/httpd/vhosts.d directory you will see something like:
vhosts.d #ls ... ... -rw-r--r--. 1 root root 356 Jan 2 23:36 vhost-http-www.z900collector.com.conf -rw-r--r--. 1 root root 356 Jan 2 23:36 vhost-http-dev.z900collector.com.conf -rw-r--r--. 1 root root 356 Jan 2 23:36 vhost-http-demo.z900collector.com.conf -rw-r--r--. 1 root root 356 Jan 2 23:36 vhost-http-test.z900collector.com.conf ... ... -rw-r--r--. 1 root root 362 Jan 2 23:39 vhost-http-www.z900collector.info.conf ... ... vhosts.d #
The file structure is easy to understand, every HTTP file is structured as:
And within each file is a basic definition of the site:
vhosts.d # cat vhost-http-www.z900collector.com.conf <VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot /var/www/z900collector.com/www <Directory /var/www/z900collector.com/www> AllowOverride All </Directory> ServerName www.z900collector.com SetEnv MAGE_RUN_CODE z900com SetEnv MAGE_RUN_TYPE store CustomLog logs/access-z900collector.com_log combined </VirtualHost> vhosts.d #
There are a few things to note, each site is in the same document root “/var/www”. Each site has a dev/demo/test and www directory that holds the specific environment and an additional “magento” directory for sites that need anything specific to Magento (the Magento eCommerce code).
So a listing of the directory:
vhosts.d # ls -la /var/www/z900collector.com/ total 32 drwxr-xr-x. 7 root root 4096 Jan 2 23:44 . drwxr-xr-x. 34 root root 4096 Jan 4 03:30 .. drwxr-xr-x. 2 root root 4096 Jan 2 23:15 demo drwxr-xr-x. 2 root root 4096 Jan 2 23:15 dev drwxr-xr-x. 2 root root 4096 Jan 2 23:15 magento drwxr-xr-x. 2 root root 4096 Jan 2 23:15 test -rw-r--r--. 1 root root 31 Aug 24 08:24 test.html drwxr-xr-x. 2 root root 4096 Jan 2 23:44 www sid1.private-pages.lan vhosts.d #
Also notice in the vhost file there are Magento specific store codes, this is an ideal way to control the use and definition of store codes, Apache will pass these onto the httpd instance when it starts a Magento site.
lastly is the log file, I use a log file for each site and for high traffic sites where I’m also doing development work I use a “access-dev.<domain-name>_log file to record activity.
So that these files are read at startup, the very last line of the httpd.conf file has:
In the middle of the httpd.conf file is the Include to read the SSL files (same format only “s” added -> vhost-https-*.conf
Where to from here?
I added this section in 2014 after writing a similar article for Conetix Cloud Hosting, the whole object of this is to support multiple stores in you Magento installation, by following this configuration you are now able to go into Magento, select “Manage Stores” and add as many sub-stores as you need for your various business needs. I use this to support multiple currency versions of the store, community groups and specials I am running. You can also use it for wholesale or “Trade” sub stores.
Enjoy! – Add “Like” the article by selecting the stars above.