► /usr/src/redhat/SOURCES/
— This directory might contain a tar
archive containing the source code for Apache and, in some cases, patches for the source. You must have installed the Apache SRPM for these files to be created.
When Apache is running, it also creates the file ht t
pd.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, RPM doesn't write over your current configuration files. RPM moves your current files and appends the extension . rpmnew
to them. For example, srm.conf
becomes srm.conf.rpmnew.
Building the Source Yourself
There are several ways to obtain the source code for Apache. Fedora provides SRPMs containing the source of Apache, which include patches to make it work better with the Fedora distribution. The most up-to-date, stable binary version for Fedora can be installed through Pirut, or by installing a source RPM from Fedora's source repository. When you install one of these SRPMs, a tar
archive containing the Apache source is created in /usr/src/redhat/SOURCES/
.
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've downloaded (for example, apache_1.3.21
).
You can also download the source directly from http://www.apache.org/. The latest version at the time of this writing, 2.2.6, is a 6MB compressed tape archive, and the latest pre-2.0 version of Apache is 1.3.31. Although many sites continue to use the older version (for script and other compatibility reasons), many new sites are migrating to or starting out with the latest stable version.
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's 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, later in this chapter, 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 from the RPM" 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 RPM 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 rpm
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 Fedora's RPM 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.
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 "Editing httpd.conf
" section, 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 files — access_log
and error_log
— but 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 Fedora is /var/log/httpd
.
A Quick Guide to Getting Started with Apache
Setting up, testing a web page, and starting Apache with Fedora 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 RPM files.
Next, set up a home page for your system by editing (as root) the file named index.html
under the /var/http/www/html
directory on your system. Make a backup copy of the original page or www
directory before you begin so that you can restore your web server to its default state if necessary.
Start Apache (again, as root
) by using the service
command with the keywords httpd
and start
, like this:
# service httpd start
You can also use the httpd
script under the /etc/rc.d/init.d/
directory, like this:
# /etc/rc.d/init.d/httpd 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 shouldn't 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 apache
no matter how it's started (by the User
and Group
settings in /etc/httpd/httpd.conf
). Despite this safe default, Apache should be started and managed by the user named apache
, defined in /etc/passwd
as:
apache:x:48:48:Apache:/var/www:/sbin/nologin
After you are satisfied with your website, use the setup
(select Services) or ntsysv
(select httpd
) command to ensure that Apache is started properly.
Starting and Stopping Apache
At this point, you have installed your Apache server with its default configuration. Fedora provides a default home page named index.html
as a test under the /var/www/html/usage
directory. The proper way to run Apache is to set system initialization to have the server run after booting, network configuration, and any firewall configuration. See Chapter 11, "Automating Tasks," for more information about how Fedora boots.
Читать дальше