This quickie tells how to run multiple websites on one server with 1 ip address using Apache Http Server version 2.x.
- Apache Http Server 2.0+ sudo apt-get install apache2 apache2-mpm-worker apache2-utils apache2.2-common (note: php.net recommends mpm-prefork for mod_php enabled servers)
- A domain (or more specifically 2, but we’ll quickly hit setting up subdomains)
- And two server roots with index files
First you have to register your domain with your hosting provider’s name servers. I use Linode and they have a pretty straightforward web utility for setting up your zone files. For the purposes of this quickie you’re looking to add hostname entries to make your zone files look something like this:
; jeffreyjason.com  $TTL 86400 @ IN SOA ns1.linode.com. umassthrower.gmail.com. ( 2010071855 14400 14400 1209600 86400 ) @ NS ns1.linode.com. @ NS ns2.linode.com. @ NS ns3.linode.com. @ NS ns4.linode.com. @ NS ns5.linode.com. @ MX 10 mail.jeffreyjason.com. @ A 184.108.40.206 www A 220.127.116.11 mail A 18.104.22.168 redmine A 22.214.171.124 xcache A 126.96.36.199
Inside your apache configuration file you need to add the following line to turn enable name based virtual hosting
Next you setup the virtual host configuration for your sites. Here is a minimalist example of 2 of mine with the cruff stripped out:
<VirtualHost *:80> ServerName jeffreyjason.com DocumentRoot /var/www/jeffreyjason.com/ </VirtualHost>
<VirtualHost *:80> ServerName redmine.jeffreyjason.com DocumentRoot /var/www/redmine/ </VirtualHost>
Finally you restart apache and, assuming your subdomain entries have propagated, you should now be serving 2 sites from one server. The process is the same with 2 separate domains, you will just have 2 separate zone files pointing to the same IP. Before we go don’t forget to add ServerAlias directives to your virtual host configurations in order to have your visitors not end up with an error message when they inevitable try to access www.subdomain.domain.tld.