Installing and Configuring Apache 2.0 You can install Apache 2.0 either by using an RPM binary distribution or by com-piling it from the source distributions.. Installing Apache using an
Trang 1Appendix D Linux Primer
LINUX IS ONE OF THE MOST POPULAR PHP platforms This appendix describes how you can install PHP and related tools on a Linux platform
Most people run the Apache Web server with Linux Because Apache works very well with PHP and MySQL, it is the platform of choice for most sites In this appen-dix, we will assume that you have a Red Hat Linux 8 system
Installing and Configuring Apache 2.0
You can install Apache 2.0 either by using an RPM binary distribution or by com-piling it from the source distributions This section describes how to install Apache using both of these methods
Installing Apache using an RPM binary
Your official Red Hat Linux distribution comes with the Apache server RPM pack-age You can install it using the following command:
rpm -ivh apache-version.i386.rpm
Once it is installed, you can access it from the /usr/local/apachedirectory
Building a custom Apache from source
Although the official copy of Red Hat Linux comes with an RPM-packaged version
of a pre-built Apache Web server, you may still want to download the latest version from the official Apache Web site at the following URL: http://www.apache.org/
If you are not in the United States, it might be faster to get Apache source and binaries from a nearby Apache mirror site Use the URL http://www.
apache.org/dyn/closer.cgi to locate a good mirror site near you Here we assume that you are getting the software from the official Apache Web site The software (both source and binaries) can be found at http://www.apache.org/
dist/httpd/
781
Trang 2You will find many recent versions of Apache distributions archived using vari-ous compression programs For example:
Apache_2.0.43.tar.gz Apache_2.0.43.tar.Z
These are both Apache Version 2.0.42 source distributions They differ in size, due to differences in compression technique Download one of these files Regardless of which format you choose to download, you need the tarutility and the gnuzipor gziputility to decompress the files For example, to decompress the Apache 2.0.43.tar.gzfile on a Red Hat 8.0 system, use the following command:
tar xvzf apache_2.0.43.tar.gz
Alternately, you could use the following:
gzip -d apache_2.0.43.tar.gz tar xvf apache_2.0.43.tar
These commands decompress and extract all the files in a subdirectory while keeping the relative path for each file intact
Once you have extracted the source into a directory of your choice, you are ready to configure and compile your custom copy of Apache You can configure
Apache manually, or you can use the new Autoconf-style interface called APACI.
We prefer the APACI method because it is quicker and requires less knowledge of Apache configuration details; in other words, you have to read fewer README and INSTALL files to get the job done
In the top-level directory of the source distribution, you will find a script called
configure, which is what you need for configuring Apache using APACI You can run this script as follows:
./configure help
This enables you to see all the available options
The first step in configuring Apache is to determine where you want to install it For example, to install Apache in a directory called /usr/local/apache, you can run the configuration script as follows:
./configure prefix=/usr/local/apache
Trang 3Apache 2.0 offers three different multiprocessing modules under Linux, each of which is described in Table D-1
T ABLE D-1 MULTIPROCESSING MODULES UNDER LINUX MPM Description
perfork This makes Apache 2.0 behave very much like Apache 1.3
A parent Apache server launches an initial number of child processes Each child process services a single request
Therefore, the maximum number of simultaneous requests that can be served is limited by the value of MaxClientsdirectives
When a single child dies due to error, only a single request is lost
worker This MPM enables Apache to perform better with fewer
resources than the perforkmodel
In this MPM model, Apache launches a set of child processes whereby each child runs ThreadsPerChildnumber of threads
Max Simultaneous Clients= MaxClientsx
ThreadsPerChild
This is more scalable than the pre_forkmodel However, when
a single thread within a child dies, any requests serviced by the threads within that child also die along with the child This means that if one child dies, multiple requests are lost
perchild In this model, Apache launches a set number of processes with a
set number of threads
Max Simultaneous Clients=
NumServerx MaxThreadsPerChild
The number of child processes started depends on the value set for the NumServerdirective
Each child process creates threads as specified in the
StartThreadsdirective
Each child process maintains a pool of idle threads, ready to service requests The number of idle threads per child process is controlled by MinSpareThreadsand maxSpareThreads
Trang 4We recommend the worker model because the perchild MPM is still under test You can use the worker MPM using the with-mpm=worker option for the con-figurescript
Compiling and installing Apache
Compiling and installing Apache is very simple once you have run the configure
script Just run the make command from the top-level directory of your Apache source distribution If everything goes well, you will not see any error messages In such a case, you can install Apache by running the make install command If you get error(s) when running make, note the error message(s) and repeat the con-figuration steps
If you still have problems, go to the Apache Web site and read the FAQs to deter-mine whether you need to do something else to get Apache running In my experi-ence, the standard Apache source distribution compiles on Red Hat without a single hitch Therefore, if Apache is not working at this point, double-check your steps before you seek help from Usenet newsgroups such as comp.infosystems.www servers.unixand linux.redhat
Once you have compiled and installed Apache, you can run make clean to remove all the object files that are created during compilation
Compiling and installing Apache support tools
When you configure Apache with the configure (or config.status) script, it automatically installs a set of support tools You do not need to do anything extra
to install any of the support tools The only exception to this is the logresolve.pl
Perl script, which you need to install manually This section describes these support tools
apachectl
Using this script, you can now control Apache To learn about the command-line options it accepts, just run it without any command-line options or use the help option, For example, if you installed Apache in /usr/local/apache, you can run:
/usr/local/apache/bin/apachectl help
To start the server, run the script as follows:
/usr/local/apache/bin/apachectl start
To stop the server, run the script shown here:
/usr/local/apache/bin/apachectl stop
To restart the server, run the following:
/usr/local/apache/bin/apachectl restart
Trang 5To test the server configuration files for syntax errors, you can run the
apachectlscript as follows:
/usr/local/apache/bin/apachectl configtest
ab
This utility enables you to run benchmarks on your Web server Just run the pro-gram without any options to find out about the command-line options it takes
apxs2
This utility helps in compiling modules for dynamic loading It is not useful unless you have Dynamic Module Support (DSO) enabled on your Apache server, and your operating system supports DSO
logresolve.pl
This Perl script is not installed automatically, but you can manually copy it to an appropriate place from the src/supportdirectory of your Apache source distribu-tion This script resolves IP addresses found in an Apache log file to their host names This script also spawns child processes and uses the parent process to pro-vide caching support to speed up DNS lookups, which are often very slow
logresolve
This utility works practically the same way as the logresolve.plscript However, this executable program is installed by default To learn about the command-line syntax, just run it with -hoption
htpasswd
This utility enables you to create username/password pairs for per-directory authentication schemes To see the usage syntax, run the program without any arguments Unlike the previously mentioned support tools, this utility is installed in the bindirectory of your Apache server installation directory
dbmmanage
This utility enables you to manage based username/password pairs for DBM-based authentication schemes To see the usage syntax, run the program without any arguments This utility also is installed in the bin directory of your Apache server installation directory
htdigest
This utility enables you to create username/password pairs for MD5 digest-based authentication schemes To see the usage syntax, run the program without any arguments This utility also is installed in the bindirectory of your Apache server installation directory