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.
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:
2. You should have apache2 running. The easiest way to check is from your terminal prompt type
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
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
# Include the virtual host configurations:
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:
Options Indexes FollowSymLinks MultiViews
allow from all
ErrorDocument 404 /index.php
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Allow from all
CustomLog /var/www/docs/abc.com/log/access.log combined
Alias /doc/ “/usr/share/doc/”
Options Indexes MultiViews FollowSymLinks
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.