Difference between revisions of "Configuring an Ubuntu Linux Based Web Server"

From Techotopia
Jump to: navigation, search
(Configuring the Apache Web server for Your Domain)
(Configuring the Apache Web Server for Your Domain)
Line 36: Line 36:
  
 
== Configuring the Apache Web Server for Your Domain ==
 
== Configuring the Apache Web Server for Your Domain ==
 +
 +
The next step in setting up your web server is to configure it for your domain name. This is performed in the /etc/apache2 directory. To configure the web server open a terminal windows and change directory to /etc/apache2. In this directory you will find two sub-directories, sites-available and sites-enabled. Change directory into sites-enabled. In this directory you will find a ''default'' file which may be used as a template for your own site.
 +
 +
Copy the ''default'' file to a new file with name which matches your doamin name. For example:
 +
 +
<pre>
 +
sudo cp default myexample.com
 +
</pre>
 +
 +
Edit your myexample.com file using your favorite editor using the sudo command to ensure you have write permission to the file. The top of the file will appear as follows:
 +
 +
<pre>
 +
NameVirtualHost *
 +
<VirtualHost *>
 +
        ServerAdmin webmaster@localhost
 +
 +
        DocumentRoot /var/www/
 +
        <Directory />
 +
                Options FollowSymLinks
 +
                AllowOverride None
 +
        </Directory>
 +
        <Directory /var/www/>
 +
                Options Indexes FollowSymLinks MultiViews
 +
                AllowOverride None
 +
                Order allow,deny
 +
                allow from all
 +
                # This directive allows us to have apache2's default start page
 +
                # in /apache2-default/, but still have / go to the right place
 +
                #RedirectMatch ^/$ /apache2-default/
 +
        </Directory>
 +
 +
</pre>
 +
 +
The ''ServerAdmin'' directive defines

Revision as of 15:13, 2 July 2007

It is surprising the number of people who now host their own web sites. One ofthe reasons for this is that doing so is now relatively easy. Linux also provides a free, enterprise level operating system with everything needed to create a web server for free (with the excpetion of the hardware of course).

In this chapter we will explain how to configure an Ubuntu Linux system to act as a web server.


Contents


Requirements for Configuring a Web Server

To set up your own web site you need a computer, an operating system, a web server, a domain name, a name server and an IP address.

The computer can be any system capabable of running Linux. In terms of an operating system, we will assume you are using Ubuntu Linux. Ubuntu Linux supports the Apache web server which can easily be installed once Ubuntu is up and running. A domain name can be registered with any domain name registration service.

If your ISP provides static IP addresses then you will need to associate your domain with your static IP address. This is achieved using a name server. Some domain registration services will provide this service for you. If yours does not, you can create a free account at http://www.zoneedit.com and use their name servers to point your domain name at your styatic IP address.

If you do not have a static IP address (i.e. your ISP provides you with a dynamic address which changes frequently) then you can use one of a number of free services which map your dynamic IP address to your domain name. One such service is provided by http://www.dnsExit.com.

Once you have your domain name and your name server configured the next step is install and configure your web server.

Installing the Apache Web Server on Ubuntu Linux

The standard web server on Linux is Apache. The web server is the technology that receives requests from web browsers and servers up the requested web pages to those browsers.

The desktop version of Ubuntu Linux does not install the Apache web server by default. The first step in setting up a web server, therefore, is to install Apache. This can be performed either from the command-line or using the Synaptic Package Manager. To use the Synaptic Package Manager, click on the System menu, select Administration and and click on Synaptic Package Manager. Enter your password if prompted to do so. Click on the Search toolbar button and search for apache2. After the search complete the Apache 2 Server should be listed in the Synaptic window. Click on the toggle next to the Apache server and select Mark for installation. Finally, click on Apply in the toolbar to begin the installation.

To install Apache from the command-line start a terminal window (Applications->System Tools->Konsole) and run the following command at the command prompt:

sudo apt-get install apache2

The installing process will not only install, but also start up the web server.


Testing the Web Server

Once the installation is complete the next step is to verify the web server is up and running. To do this fireup the web browser by clicking on the Firefox logo and enter 127.0.0.1/apache2-default in the address bar (127.0.0.1 is the loop-back network address wich tells the system to connect to the local machine). The browser should load a page that reads It works!.

Congratulations, you have now installed the web server and served up what will hopefully be the first of many web pages.

Configuring the Apache Web Server for Your Domain

The next step in setting up your web server is to configure it for your domain name. This is performed in the /etc/apache2 directory. To configure the web server open a terminal windows and change directory to /etc/apache2. In this directory you will find two sub-directories, sites-available and sites-enabled. Change directory into sites-enabled. In this directory you will find a default file which may be used as a template for your own site.

Copy the default file to a new file with name which matches your doamin name. For example:

sudo cp default myexample.com

Edit your myexample.com file using your favorite editor using the sudo command to ensure you have write permission to the file. The top of the file will appear as follows:

NameVirtualHost *
<VirtualHost *>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/
        </Directory>

The ServerAdmin directive defines