Ubuntu Server – Configure and Run Multiple Websites on One Server

Here’s a simple tutorial to get many websites running on one ubuntu server
Let’s say you have root access to your own server and want to run many websites on it. If you have Ubuntu Server running with Apache, I will show you in a few easy steps how to configure and run as many websites on your server as the load can handle.

Follow these simple instructions and your additional websites will up and running immediately.

Pre-Install Checks
1. You should have Ubuntu Server 8.04 (or later) running.  You can check your Ubuntu server version by typing this in a terminal prompt   cat  /etc/lsb-release
You should see:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION=”Ubuntu 8.04.1″

2. You should have apache2 running. The easiest way to check is from your terminal prompt type
cd /etc/apache2
if you are now in the /etc/apache2 directory, then we can assume it’s on your server.

Simple Steps to run multiple websites
First, prepare the directories on your server to point the new domain you want to add.
I usually do something like this:
/var/www/docs/ is the base
domain-name.com/ is the domain
public for files that are accessible to apache and the world
private for files that are accessible to apache only (like crons, included header files, etc…)
log for a place to log the entries and errors
backup for a place to save files

For example, if you are adding abc.com, you would create the following using terminal
cd /var/www/docs
mkdir abc.com
cd abc.com
mkdir public private log backup

Next, let’s go to apache and tell it we are ready to add more domains to the configuration.

Type in your terminal cd /etc/apache2
open the file (I use vi) vi apache2.conf
Look for

# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/
NameVirtualHost *:80

If it isn’t there, add it. Then save the file. (always make a backup before making changes to any server file)

Next, let’s go to the existing website configuration directory and add our new domain
Type in the terminal cd /etc/apache2/sites-available
You’ll probably see a file default or 000-default
Note: The default configuration on apache is what tells the server where to look for index.html each time someone types in the ip address of your server, or the domain name you have already configured. It also tells apache where to log each server event. After you’ve added other domains, you may want to revisit the default file and decide which domain traffic should go to in the event the ip address is entered, and not the domain name itself.

Next, let’s prepare another file to tell apache there’s another domain to look for aside from the default.
Copy the default file to a new file with the name of the additional website(s) you want to run on this server. For example, let’s say you want to have abc.com on this server. you would type this command cp default abc.com

Next, edit the file you’ve just created to point to the directory on your server where you’d like to manage the files for that domain.
My apache config files look like this:


#
ServerAdmin webmaster@abc.com
DocumentRoot /var/www/docs/abc.com/public
ServerName abc.com
ServerAlias www.abc.com

Options FollowSymLinks
AllowOverride None


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all


RewriteEngine On
RewriteBase /
ErrorDocument 404 /index.php

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all

ErrorLog /var/www/docs/abc.com/log/error.log
LogLevel warn
CustomLog /var/www/docs/abc.com/log/access.log combined
ServerSignature On
Alias /doc/ “/usr/share/doc/”

Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128

You will want to edit the file to meet your own needs. I copied mine here as an example. It would be better for you to edit the new file you’ve copied from your default.

Take care to enter the exact directory names of your new domain and make sure nothing is misspelled. Apache is not forgiving at all. When you try to reload apache, if one directory name is missing, the entire apache server will crash until you fix the offending entry.

Once you are sure the configuration file is accurate, save it and let’s move on.
From terminal, type in cd /etc/apache2
Next, type in a2ensite abc.com (the name of your domain instead of abc)
a2ensite is the command that creates a symlink for apache from sites-available to sites-enabled and tells apache you’re ready to accept traffic for this domain
Assuming you typed everything correctly, you should get a message back
Site abc.com installed; run /etc/init.d/apache2 reload to enable.
Then, simply reload apache
If you get
* Reloading web server config apache2 [ OK ]
Then you should be up and running with your new web domain
Put a sample file in your new domain’s public directory.
For example, open a new file index.html vi /var/www/docs/abc.com/public/index.html
edit it with a message like You got to the new domain 🙂
Save the file, then test by typing in your new domain in a web browser and seeing if that message appears.

To add more domains, simply start at the top of this page again.

We have tried to make this primer as straightforward as possible. As with anything, there is always a deeper level of understanding and things you can configure. First, we got the domains up, next we can tackle other issues like security, ports, etc… which will be discussed in future posts.

We hope you have found this useful, please add your comments and suggestions on how to improve the steps provided here.

4 thoughts on “Ubuntu Server – Configure and Run Multiple Websites on One Server”

Leave a Reply

Your email address will not be published. Required fields are marked *