Part VII) Setting Up a Virtual Server (Multiple Web Sites, One Server)

Hey, we did real good getting a web site on the web. Hopefully you spent less than a day so far. Let's plan for some immediate expansion -- 5 web sites!

Remember, DynDNS will allow us 5 free dynamically redirected URLs. Why not use each one for its own web site !?

Multiple web sites on the same server are called "virtual hosts." The way to go about this differs for each version of Ubuntu and Apache, so my comments are directed only toward Ubuntu 6.06 LTS (Dapper Drake) and Apache2. A rough guide is presented at:

http://www.debuntu.org/2006/02/22/7-virtual-hosting-using-apache-2

but it has some mistakes that took me a while to figure out, so I'll outline the steps here as well.

First, it is a good idea to put each web page in a separate subdirectory in the root /var/www/ folder.

While still in your regular login, make subdirectories for each webpage you might create. They could be, for example, /var/www/foobar1/, /var/www/foobar2/, /var/www/foobat3/, /var/www/fooball4/, and /var/www/toaster5/.

(Don't create these folders as the root user, or they will have root privileges only. Create them using your regular login id.)

Now, in previous versions of Apache you could "simply" edit the httpd.conf configuration file to enable virtual hosts, but this is no longer done with Apache2. This took me a loooong time to find out.

Instead, a scheme of individual configuration files for each virtual host web site is used, each placed in the /etc/apache2/sites-available folder. The guide referenced above details the basics.

Now, the /etc/apache2/sites-available folder is restricted to the root user, so we will have make any changes to it while logged in as root. We'll be making a lot of changes, so it is easiest to log out and re-login as the root user using the Gnome login screen for this
(System --> Quit --> Log Out --> login as root)

Once you have done this, open the Gedit Text Editor
(Applications --> Accessories --> Text Editor).

Now copy the following to the Text Editor. Replace foobar1.dyndns.org with the URL of your web site (the one you chose at DynDNS). Also replace fido with your user login. Replace /var/www/foobar1 with the folder you created above for the particular web site that will be used to store the web pages you want referenced by the URL. (In the example, the URL foobar1.dyndns.org (as specified in ServerName and ServerAlias) should have the Document Root /var/www/foobar1 because that's where its web pages will be stored.)

[Note that this file is different than the one on the referenced web page above. Theirs will not work.]

-----------------------------------------------------------
<VirtualHost *>
ServerName foobar1.dyndns.org
ServerAdmin fido@localhost
#We want to be able to access the web site using foobar1.dyndns.org or www.foobar1.dyndns.org
ServerAlias foobar1.dyndns.org www.foobar1.dyndns.org
#
DocumentRoot /var/www/foobar1

#if using awstats
#ScriptAlias /awstats/ /usr/lib/cgi-bin/

#we want specific log file for this server
CustomLog /var/log/apache2/foobar1-access.log combined
</VirtualHost>
-------------------------------------------------------------

Now save this file as foobar1.conf in the /etc/apache2/sites-available folder.

Copy the file 4 times (if you will have 4 extra web sites, for a total of 5). Rename the copies appropriately, such as foobar2.conf, foobat3.conf, fooball4.conf, and toaster5.conf. Edit each one so that the entries are appropriate. (That is, change the ServerName, ServerAlias, and DocumentRoot lines to reflect the proper values. foobar2.conf, for example, should have ServerName foobar2.dyndns.org, DocumentRoot /var/www/foobar2, and the (by now hopefully obvious) ServerAlias settings.)

Interestingly, creating these configuration files doesn't actually enable them.

I guess that is so you can decide which web sites should be active from day to day without actually changing the configuration files.

To actually activate the virtual host web site, you must Make a Link to these configuration files in the
/etc/apache2/sites-enabled folder.

(This is the equivalent to making a Shortcut in Windows, although the concept of a "symbolic link" is a Unix one from long ago).

Making a symbolic link can be done in two ways. In the command line terminal, the command

ln -s /folder1/file1 /folder2

is the time-honored Linux/Unix way of doing this.

The other way is to right click on a file in the Nautilus File Browser and select "Make Link." (Again, this is like creating a Shortcut in Windows.) The new Link should then moved to the folder in which you want it, and renamed appropriately.

To enable the virtual host foobar1 (which corresponds to the URL foobar1.dyndns.org), right click on the foobar1.conf file in the
/etc/apache2/sites-available
folder and select "Make Link." Now drag or otherwise move the resulting file "Link to foobar1.conf" to the folder
/etc/apache2/sites-enabled.

Once in that folder, rename the link from "Link to foobar1.conf" to "foobar1.conf" again.

Now foobar1.dyndns.org is enabled as a virtual host web site.

Repeat, making links for the other 4 configuration files in
/etc/apache2/sites-available,
dragging the links to the
/etc/apache2/sites-enabled
folder and renaming them to their original names.

Now you all have 5 virtual host web sites enabled in Apache.

Each will be reachable from their own URL and directed to the web pages contained in their respective folders by Apache.

Well, they will once you have restarted Apache, that is.

In the command line terminal, enter

/etc/init.d/apache2 restart

Now logout as root user, and log back in as a regular user.

2) Create web pages for each virtual host web site

To test if everything works properly, you will need at least one index.html web page in each of the subfolders you created. You can copy the default index.html in /var/www to each subfolder and then edit it with a text editor. Somewhere on each individual index.html put some text that has the title of the web page in it.

For example, copy index.html to the /var/www/foobar1 folder. Use Gedit Text Editor to add "foobar1" to the end of the line "Seeing this text instead of the website you were expecting?" and save.

Now start Firefox and enter your URL foobar1.dyndns.org in the address bar. If everything is working, you index.html should appear, with the line "Seeing this text instead of the website you were expecting? foobar1" in the middle. If this works, then repeat for each of your web sites, until each folder has its own index.html. Then, when you login to foobar2.dyndns.org you should see "Seeing this text instead of the website you were expecting? foobar2", and so on.

If each URL comes up with its own index.html, then everything works great. Time to create some web content!

3) Create your web content

Don't underestimate your achievement. In probably less than a day you have set up a dual-booting computer with 5 separate web pages available on the Internet. (Some would say that was the easy part.) You still have to create a website.

Software for creating websites has progressed tremendously. You can still write very nice web sites using very simple HTML and a text editor like Gedit. Many web sites are still created in this fashion. These simple web sites can be viewed by almost everyone. They are best for content with static text and pictures, which in reality is at least 1/2 of all web sites.

OpenOffice Writer has a simple way to create a basic web site, complete with CSS style sheet, but the results are not very attractive.

There are some open source programs for Linux that can create quite fancy web page content. Quanta and Joomla seem to be the most popular. I am still evaluating these, so you might learn more about them than I do very quickly.

The most promising web content management system appears to be Drupal. This is a system where contributors create modules, such as a poll module, or a blog module, or a music streaming module. You download the individual modules to your web folder, and the basic Drupal program incorporates each module into your web page, using a MySQL database and the PHP scripting language (two components of your LAMP server) to keep track of the details.

Most of the web sites I have seen using Drupal look impressive. They share many features but then can be individualized extensively.

The next section will detail my adventures with Drupal.

| Home page | Introduction | Chapter I: Installing Windows on a dual-boot computer | Chapter II: Installing Ubuntu Linux Server on a dual-boot computer | Chapter III: Adding the Ubuntu Desktop on a dual-boot computer | Chapter IV: Spiffing up Ubuntu Linux | Chapter V: Ubuntu/Windows shared networks | Chapter VI: Setting up a Web Site on Ubuntu | Chapter VII: Ubuntu/Apache Virtual Hosts (Multiple web sites, single server) | Chapter VIII: Installing Drupal Content Managment System | Chapter IX: Installing Vista Office EHR | Chapter X: Installing an Office Surveillance Security System with Ubuntu | Chapter XI: Installing an open source Groupware Server | Chapter XII: Installing a non-linear video editor for presentations |


Hosted by www.Geocities.ws

1