Installing the Apache Web Server

On GNU/Linux systems, no hard line exists between desktop and server machines. You can install server packages on your regular PC without having to change the operating system. A dedicated server machine runs only those packages required for the task, which greatly simplifies security and administration. However, by using localhost, the system's network address for itself, you can run both a server and a desktop with a web browser on the same machine. This approach is valid for experimentation or testing a site before it's copied to the production server. If you have a broadband Internet connection, you can usually serve a limited amount of material from your desktop PC or laptop without running into trouble. Your Internet Service Provider (ISP) may have set monthly limits on the amount of data that you can serve from a domestic Internet connection without a financial penalty; if in doubt, check the figures first.

Most web sites sit on dedicated servers in ISP data centers because they benefit from better bandwidth connections to the Internet than are typically available at home. Also, you don't have to leave your home PC switched on 24 hours a day, 7 days a week because web site visitors can arrive at any time. A good server installation benefits from multiple Internet connections, back-up power supplies, and a skilled network or system administrator on site. All these things help keep web sites going around the clock, when a simpler domestic setup could go down.

To get started, you need to install Apache (GNU/Linux, Windows, Mac), the most popular web server software on the Internet. The easiest way to do this on Ubuntu is to install the apache2 metapackage, using System > Administration > Synaptic Package Manager (see Figure 12-1).


,Package | Installed Version

Latest Version




Realtime Apache monitoring tool




Module to remove IP from apacheZ's logs


¿3 apache2.2-cornmon


Apache HTTP Server common files

'J libapache2-mod-auth-parn


module for Apache2 which authenticate usl

□ v libapache2-mod-auth-pgsql


Module for Apache2 which provides pgsql a


■j libapache2-mod-auth-plain

2.0.48-4-2.2ubuntu Module for Apache2 which provides plainte

5 apache2


Apache HTTP Server metapackage

j apache2-doc


Apache HTTP Server documentation


0.0.19+p4.2340-l.] BitTorrent tracker for the Apache2 web serv





1 i bco nfi g - a pa chef orm a t- perl


use Apache format config files

O apache2-threaded-dev


Apache development headers - threaded M




Apache2 module to get MIME info from file:

Figure 12-1. Install Apache 2 using its metapackage, for instant gratification.

Figure 12-1. Install Apache 2 using its metapackage, for instant gratification.

This installs all the basic packages that the second major release of the Apache web server requires, without your having to specify them individually. Other GNU/Linux distributions have Apache packages available, and Windows and Mac users can download the software from

Now, open a web browser (which on Ubuntu is Mozilla Firefox by default), type the URL http://localhost/ into the location bar, and press the Enter key on your keyboard. If Apache has been installed correctly, a simple but encouraging web page is served by your PC or laptop (see Figure 12-2). If you know the IP address of your machine on the local network, which is in my case, you can type this into the location bar instead of localhost.

Figure 12-2. Apache confirms that it has been installed correctly with this very simple page.

This Apache test page can't be accessed by anyone else yet, unless your broadband router or other Internet connection is configured to allow incoming traffic on port 80, the traditional port for serving web pages. To enable public access to your computer, and all that implies, check the documentation that came with your router to see if it allows port forwarding.

Open a terminal (in Ubuntu, choose Applications > Accessories > Terminal), and change to the directory where web pages are kept by default. On Ubuntu, this is the /var/www directory:

cd /var/www

Then, issue a "list directory contents" command, which is ls on GNU/Linux. You should find the index.html file that you just saw the result of in the web browser. Using the -l switch at the end of the list command reveals more details about the index.html file (see Figure 12-3).

File Edit View Terminal Help [email protected] /var/www [email protected] :/var/www$ Is index.html daniel(adaniel-laptop :/var/wwwS Is -I total 4-

-rw-r-r-- 1 root root 128 2009-08-B4 14:51 index.html [email protected]:/var/www$ |

Figure 12-3. The ls -l command tells you more about the file.

In addition to the date the file was created or modified, this command informs you that the index.html file belongs to the user root and the group root. This root is the traditional name for the administrator account on a GNU/Linux system. Ubuntu doesn't have a root user account that you can log in to, but you can assume administrative powers using the sudo command instead, as you saw in earlier chapters. You need these powers to edit the index. html file that belongs to root because it's not one of your personal files, which are normally in your /home directory.

To perform the edit, you can use a command-line editing program called GNU nano (GNU/Linux, Windows, Mac). The nano program should be installed by default on any GNU/Linux or Apple OS X system. Windows users can download it from It may seem a little old-school, but nano is an awesome program to have in your toolkit when you're working directly on a remote server on the other side of the Internet, which may have no desktop. In the terminal, type the following:

sudo nano index.html

The sudo prefix elevates the command to administrator status. Otherwise, nano can read the file for you but not write out any edits you make. Ubuntu prompts you for your login password, to make sure you're not a random person who happens to be passing the keyboard, ready to abuse those root powers. Then, the nano editor starts up inside the terminal, showing you the HTML source code of the file specified (see Figure 12-4).

Figure 12-4. GNU nano is a very useful command-line text editor for administering web servers.

To make edits in nano, use the cursor keys to move around the text file, change the part you want, and then press Ctrl+O followed by the Enter key to write out a new copy of the file (save it to disk). (Most commands in nano are accomplished with Ctrl+key combinations, which are listed at the lower edge of the terminal window.) If you want to prove that the web server is running, edit the index.html file, write it out, and click the refresh button on your web browser (see Figure 12-5). Use Ctrl+X to close nano when you're done.

Figure 12-5. Editing Apache's default web page shows that the web server is really running.

If you've done any manual web-page editing, the HTML syntax of the file should be familiar—all page text is enclosed in tags made from angled brackets, with a corresponding closing tag. For example, text enclosed by the tags <hl> to </hl> represents a large headline font.

0 0

Post a comment