Second Day at KAMP: Multisites

10 Mar 2008
Posted by ejhildreth

Now that KAMP has successfully been set up on a Kubuntu box, setting up multiple sites on one server is the next logical step. This allows you to do Drupal testing in multiple versions/setups at the same time on one localhost server. To begin, open up Konsole (command line utility) and change to the Apache2 sites-available directory (this is where Apache stores the setup files for each Virtual Host):

cd /etc/apache2/sites-available/

Next, login as root and copy the existing default setup file and name it to the "server" you want to use:

sudo -s (prompts you for your password)
cp default exampleSite

Using your favorite text editor, modify the newly copied file so that it points to the correct files (using VI in this example):

vi exampleSite

Modify/Add the following lines:

NameVirtualHost * to NameVirtualHost exampleSite:80
<VirtualHost *> to <VirtualHost exampleSite:80>
Add ServerName exampleSite
DocumentRoot /var/www/ to DocumentRoot /var/www/exampleSite/
<directory /var/www/> to <directory /var/www/exampleSite/>

To let Apache "know" about the site and make it active, you need to create a symbolic link from the sites-available directory in the sites-available directory:

cd /etc/apache2/site-enabled/
ln -s /etc/apache2/sites-available/exampleSite .

For the changes to take effect, restart Apache

apache2 -k restart

To be able to type in quickly avaiable URL's into the browser and have Apache take you to the correct site, you need to modify your HOSTS file. By default, localhost (IP address 127.0.0.1) is already in this file. Since Apache is now set up to access and handle multiple sites, you simply need to add the additional Virtual Servers to your HOSTS file to have the browser point to the correct location:

vi /etc/hosts

Using the localhost line as an example, add additional lines to the file (one for each Virtual Host):

127.0.0.1 exampleSite