Installing the Apache Server


You can install Apache through APT or build it yourself from source code. The Apache source builds on just about any UNIX-like operating system and on Win32.

If you are about to install a new version of Apache, you should shut down the old server. Even if it's unlikely that the old server will interfere with the installation procedure, shutting it down ensures that there will be no problems. If you do not know how to stop Apache, see the "Starting and Stopping Apache" section later in this chapter.

Installing with APT

You can find the Apache package on the Ubuntu installation media, on the Ubuntu FTP server, or at one of its many mirror sites. Updated packages usually contain important bug and security fixes. When an updated version is released, install it as quickly as possible to keep your system secure.

Note

Check the Apache site for security reports. Browse to http://httpd.apache.org/ security_report.html for links to security vulnerabilities for Apache 1.3, 2.0, and 2.2. Subscribe to a support list or browse through up-to-date archives of all Apache mailing lists at http://httpd.apache.org/mail/ (for various articles) or http://httpd.apache.org/lists.html (for comprehensive and organized archives).


Caution

You should be wary of installing experimental packages, and never install them on production servers (that is, servers used in "real life"). Very carefully test the packages beforehand on a host that is not connected to a network!


The easiest way to use APT is through Synaptic, which is under the System > Administration menu. Search for apache2 and select it, and Synaptic will add the required dependencies.

Alternatively you can install Apache through a .deb package with the command-line dpkg tool by typing the following:

dpkg -i latest_apache.deb 


where latest_apache.deb is the name of the latest Apache package. For more information on installing packages with APT and dpkg, refer to Chapter 7, "Managing Software."

The Apache package installs files in the following directories:

  • /etc/apache2 This directory contains the Apache configuration file, httpd.conf.

  • /etc/init.d/ The tree under this directory contains the system startup scripts. The Apache package installs a startup script named apache2 for the web server under the /etc/init.d directory. This script, which you can use to start and stop the server from the command line, also automatically starts and stops the server when the computer is halted, started, or rebooted.

  • /var/www The package installs the default server icons, Common Gateway Interface (CGI) programs, and HTML files in this location. If you want to keep web content elsewhere, you can do so by making the appropriate changes in the server configuration files.

  • /var/www/manual/ If you've installed the apache-manual package, you'll find a copy of the Apache documentation in HTML format here. You can access it with a web browser by going to http://localhost/manual/.

  • /usr/share/man Ubuntu's Apache package also contains manual pages, which are placed underneath this directory. For example, the apache2 man page is in section 8 of the man directory.

  • /usr/sbin The executable programs are placed in this directory. This includes the server executable itself, as well as various utilities.

  • /usr/bin Some of the utilities from the Apache package are placed herefor example, the htpasswd program, which is used for generating authentication password files.

  • /var/log/httpd The server log files are placed in this directory. By default, there are two important log files (among several others): access_log and error_log. However, you can define any number of custom logs containing a variety of information. See the section "Logging," later in this chapter, for more detail.

When Apache is being run, it also creates the file apache2.pid, containing the process ID of Apache's parent process in the /var/run/ directory.

Note

If you are upgrading to a newer version of Apache, APT does not write over your current configuration files.


Building the Source Yourself

You can download the source directly from http://www.apache.org/. The latest version at the time of this writing (2.2.0) is a 6MB compressed tape archive, and the latest pre-2.0 version of Apache is 1.3.34. Although many sites continue to use the older version (for script and other compatibility reasons), many new sites are migrating to or starting out using the latest stable version.

After you have the tar file, you must unroll it in a temporary directory, such as /tmp. Unrolling this tar file creates a directory called apache_version_number, where version_number is the version you have downloaded (for example, apache_1.3.34).

There are two ways to compile the sourcethe old, familiar way (at least, to those of us who have been using Apache for many years) by editing Makefile templates, and the new, easy way using a configure script. You will first see how to build Apache from source the easy way. The configure script offers a way to have the source software automatically configured according to your system. However, manually editing the configuration files before building and installing Apache provides more control over where the software is installed and which capabilities or features are built in to Apache.

Tip

As with many software packages distributed in source code form for Linux and other UNIX-like operating systems, extracting the source code results in a directory that contains a README and an INSTALL file. Be sure to peruse the INSTALL file before attempting to build and install the software.


Using ./configure to Build Apache

To build Apache the easy way, run the ./configure script in the directory just created. You can provide it with a --prefix argument to install it in a directory other than the default, which is /usr/local/apache/. Use this command:

# ./configure --prefix=/preferred/directory/ 


This generates the Makefile that is used to compile the server code.

Next, type make to compile the server code. After the compilation is complete, type make install as root to install the server. You can now configure the server via the configuration files. See the "Runtime Server Configuration Settings" section for more information.

Tip

A safer way to install a new version of Apache from source is to use the ln command to create symbolic links of the existing file locations (listed in the "Installing with APT" section earlier in this chapter) to the new locations of the files. This method is safer because the default install locations are different from those used when the package installs the files. Failure to use this installation method could result in your web server process not being started automatically at system startup.

Another safe way to install a new version of Apache is to first back up any important configuration directories and files (such as /etc/httpd) and then use the apt-get command to remove the server. You can then install and test your new version and, if needed, easily restore your original server and settings.

It is strongly recommended that you use Ubuntu's version of Apache until you really know what happens at system startup. No "uninstall" option is available when installing Apache from source!


Apache File Locations After a Build and Install

Files are placed in various subdirectories of /usr/local/apache (or whatever directory you specified with the --prefix parameter) if you build the server from source. Before version 1.3.4, files were placed in /usr/local/etc/httpd.

The following is a list of the directories used by Apache, as well as brief comments on their usage:

  • /usr/local/apache/conf This contains several subdirectories and the Apache configuration file, httpd.conf. See the section "Editing httpd.conf" later in this chapter to learn more about configuration files.

  • /usr/local/apache The cgi-bin, icons, and htdocs subdirectories contain the CGI programs, standard icons, and default HTML documents, respectively.

  • /usr/local/apache/bin The executable programs are placed in this directory.

  • /usr/local/apache/logs The server log files are placed in this directory. By default, there are two log filesaccess_log and error_logbut you can define any number of custom logs containing a variety of information (see the "Logging" section later in this chapter). The default location for Apache's logs as installed by Ubuntu is /var/log/httpd.

A Quick Guide to Getting Started with Apache

Setting up, testing a web page, and starting Apache using Ubuntu can be accomplished in just a few steps. First, make sure that Apache is installed on your system. Either select it during installation or install the server and related package files (refer to Chapter 7 if you need to install the server software).

Next, set up a home page for your system by editing (as root) the file named index.html under the /var/www directory on your system. Make a backup copy of the original page or www directory before you begin so you can restore your web server to its default state if necessary.

[View full width]

Start Apache through the Services window (under System, Administration from the menu bar), making sure to enable "Web Server".


You can also use the apache2 script under the /etc/init.d/ directory, like this:

sudo /etc/init.d/apache2 start 


You can then check your home page by running a favorite browser and using localhost, your system's hostname, or its Internet Protocol (IP) address in the URL. For example, with the links text browser, use a command line like this:

# links http://localhost/ 


For security reasons, you should not start and run Apache as root if your host is connected to the Internet or a company intranet. Fortunately, Apache is set to run as the user and group www-data no matter how it is started (by the User and Group settings in /etc/apache2/httpd.conf). Despite this safe default, Apache should be started and managed by the user named apache, defined in /etc/passwd as

www-data:x:33:33:www-data:/var/www:/sbin/nologin 


After you are satisfied with your website, use the Services configuration dialog to ensure that Apache is started.




Ubuntu Unleashed
Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition)
ISBN: 0672333449
EAN: 2147483647
Year: 2006
Pages: 318

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net