| Goals for this chapter: | rpm packages covered in this chapter:
|
|
|
|
Apache is the most used and famous HTTP Linux daemon. Developed by a group of enthusiast, Apache today is the most used HTTP daemon Web server in the World.
At boot time, when your system present the message:
Starting httpd:
[ OK ]
The service starts. You can check this service running the command:
[root@ftosx1 /root]# ps ax | grep httpd
2377 ? S
0:00 httpd
2380 ? S
0:00 httpd
2381 ? S
0:00 httpd
2382 ? S
0:00 httpd
2383 ? S
0:00 httpd
2384 ? S
0:00 httpd
2385 ? S
0:00 httpd
2386 ? S
0:00 httpd
2387 ? S
0:00 httpd
2443 pts/2 S
0:00 grep httpd
[root@ftosx1 /root]#
The Apache configuration files are located in the directory: "/etc/httpd"
[root@ftosx1 httpd]# ls -alR
.:
total 7
drwxr-xr-x 3 root
root 120 Mar 29 17:53
.
drwxr-xr-x 60 root root
6192 Jun 5 15:54 ..
drwxr-xr-x 7 root
root 304 May 20 10:23
conf
lrwxrwxrwx 1 root
root 19 May
20 10:05 logs -> ../../var/log/httpd
lrwxrwxrwx 1 root
root 20 May
20 10:05 modules -> ../../usr/lib/apache
./conf:
total 71
drwxr-xr-x 7 root
root 304 May 20 10:23
.
drwxr-xr-x 3 root
root 120 Mar 29 17:53
..
lrwxrwxrwx 1 root
root 37 May
20 10:23 Makefile -> ../../../usr/share/ssl/certs/Makefile
-rw-r--r-- 1 root
root 348 Mar 29 17:53
access.conf
-rw-r--r-- 1 root
root 41430 Mar 29 17:53 httpd.conf
-rw-r--r-- 1 root
root 12441 Mar 29 17:52 magic
-rw-r--r-- 1 root
root 357 Mar 29 17:53
srm.conf
drwx------ 2 root
root 104 May 20 10:23
ssl.crl
drwx------ 2 root
root 440 May 20 10:23
ssl.crt
drwx------ 2 root
root 80 May
20 10:23 ssl.csr
drwx------ 2 root
root 256 May 20 10:23
ssl.key
drwx------ 2 root
root 152 May 20 10:23
ssl.prm
./conf/ssl.crl:
total 9
drwx------ 2 root
root 104 May 20 10:23
.
drwxr-xr-x 7 root
root 304 May 20 10:23
..
-rw-r--r-- 1 root
root 1569 Mar 29 17:53
Makefile
-rw-r--r-- 1 root
root 320 Mar 29 17:53
README.CRL
./conf/ssl.crt:
total 269
drwx------ 2 root
root 440 May 20 10:23
.
drwxr-xr-x 7 root
root 304 May 20 10:23
..
lrwxrwxrwx 1 root
root 19 May
20 10:23 0cf14d7d.0 -> snakeoil-ca-dsa.crt
lrwxrwxrwx 1 root
root 16 May
20 10:23 5d8360e1.0 -> snakeoil-dsa.crt
lrwxrwxrwx 1 root
root 16 May
20 10:23 82ab5372.0 -> snakeoil-rsa.crt
-rw-r--r-- 1 root
root 1522 Mar 29 17:52
Makefile
-rw-r--r-- 1 root
root 1386 Mar 29 17:52
README.CRT
-r-------- 1 root
root 242153 Mar 29 17:52 ca-bundle.crt
lrwxrwxrwx 1 root
root 19 May
20 10:23 e52d41d0.0 -> snakeoil-ca-rsa.crt
-rw------- 1 root
root 1464 May 20 10:23
server.crt
-r-------- 1 root
root 1472 Mar 29 17:52
snakeoil-ca-dsa.crt
-r-------- 1 root
root 1192 Mar 29 17:52
snakeoil-ca-rsa.crt
-r-------- 1 root
root 1452 Mar 29 17:52
snakeoil-dsa.crt
-r-------- 1 root
root 1176 Mar 29 17:52
snakeoil-rsa.crt
./conf/ssl.csr:
total 5
drwx------ 2 root
root 80 May
20 10:23 .
drwxr-xr-x 7 root
root 304 May 20 10:23
..
-rw-r--r-- 1 root
root 926 Mar 29 17:53
README.CSR
./conf/ssl.key:
total 25
drwx------ 2 root
root 256 May 20 10:23
.
drwxr-xr-x 7 root
root 304 May 20 10:23
..
-rw-r--r-- 1 root
root 1207 Mar 29 17:53
README.KEY
-rw------- 1 root
root 891 May 20 10:23
server.key
-r-------- 1 root
root 668 Mar 29 17:53
snakeoil-ca-dsa.key
-r-------- 1 root
root 887 Mar 29 17:53
snakeoil-ca-rsa.key
-r-------- 1 root
root 668 Mar 29 17:53
snakeoil-dsa.key
-r-------- 1 root
root 891 Mar 29 17:53
snakeoil-rsa.key
./conf/ssl.prm:
total 13
drwx------ 2 root
root 152 May 20 10:23
.
drwxr-xr-x 7 root
root 304 May 20 10:23
..
-rw-r--r-- 1 root
root 516 Mar 29 17:53
README.PRM
-r-------- 1 root
root 455 Mar 29 17:53
snakeoil-ca-dsa.prm
-r-------- 1 root
root 455 Mar 29 17:53
snakeoil-dsa.prm
[root@ftosx1 httpd]#
The Apache httpd daemon haves a configuration file called: httpd.conf.
In this files are present all the
The Server Root is the directory where is located the HTTP Apache
hierarchy.
#
# This may also be "None", "All", or any
combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI",
or "MultiViews".
#
# Note that "MultiViews" must be named
*explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks
#
# This controls which options the .htaccess
files in directories can
# override. Can also be "All", or any
combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride None
#
# Controls who can get stuff from this
server.
#
Order allow,deny
Allow from all
</Directory>
#
# "/var/www/cgi-bin"
should be changed to whatever your ScriptAliased
# CGI directory exists,
if you have that configured.
#
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<Directory "/var/www/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule mod_autoindex.c>
#
# FancyIndexing is
whether you want fancy directory indexing or standard
#
IndexOptions FancyIndexing
NameWidth=*
#
# AddIcon* directives
tell the server which icon to show for different
# files or filename
extensions. These are only displayed for
# FancyIndexed directories.
#
AddIconByEncoding (CMP,/icons/compressed.gif)
x-compress x-gzip
AddIconByType (TXT,/icons/text.gif)
text/*
AddIconByType (IMG,/icons/image2.gif)
image/*
AddIconByType (SND,/icons/sound2.gif)
audio/*
AddIconByType (VID,/icons/movie.gif)
video/*
AddIcon /icons/binary.gif
.bin .exe
AddIcon /icons/binhex.gif
.hqx
AddIcon /icons/tar.gif
.tar
AddIcon /icons/world2.gif
.wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif
.Z .z .tgz .gz .zip
AddIcon /icons/a.gif
.ps .ai .eps
AddIcon /icons/layout.gif
.html .shtml .htm .pdf
AddIcon /icons/text.gif
.txt
AddIcon /icons/c.gif
.c
AddIcon /icons/p.gif
.pl .py
AddIcon /icons/f.gif
.for
AddIcon /icons/dvi.gif
.dvi
AddIcon /icons/uuencoded.gif
.uu
AddIcon /icons/script.gif
.conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif
.tex
AddIcon /icons/bomb.gif
core
AddIcon /icons/back.gif
..
AddIcon /icons/hand.right.gif
README
AddIcon /icons/folder.gif
^^DIRECTORY^^
AddIcon /icons/blank.gif
^^BLANKICON^^
#
# DefaultIcon is which
icon to show for files which do not have an icon
# explicitly set.
#
DefaultIcon /icons/unknown.gif
#
# AddDescription allows
you to place a short description after a file in
# server-generated
indexes. These are only displayed for FancyIndexed
# directories.
# Format: AddDescription
"description" filename
#
#AddDescription "GZIP
compressed document" .gz
#AddDescription "tar
archive" .tar
#AddDescription "GZIP
compressed tar archive" .tgz
#
# ReadmeName is the
name of the README file the server will look for by
# default, and append
to directory listings.
#
# HeaderName is the
name of a file which should be prepended to
# directory indexes.
#
# If MultiViews are
amongst the Options in effect, the server will
# first look for name.html
and include it if found. If name.html
# doesn't exist, the
server will then look for name.txt and include
# it as plaintext if
found.
#
ReadmeName README
HeaderName HEADER
#
# IndexIgnore is a
set of filenames which directory indexing should ignore
# and not include in
the listing. Shell-style wildcarding is permitted.
#
IndexIgnore .??* *~
*# HEADER* README* RCS CVS *,v *,t
</IfModule>
These icons are the icons that apache display browsing directories in the browser?

SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
Apache haves also log files that creates the statistics for hits and errors. These log files are present in the dir: "/etc/httpd/logs". Is possible also to modify the format for the file.
These are some entries that regards the file:
ErrorLog logs/error_log
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error,
crit,
# alert, emerg.
#
LogLevel warn
#
# The following directives define some format nicknames for
use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#
# The location and format of the access logfile (Common Logfile
Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if
you *do*
# define per-<VirtualHost> access logfiles, transactions
will be
# logged therein and *not* in this file.
#
# CustomLog /var/log/httpd/access_log common
CustomLog logs/access_log combined

If you apply some change to the Apache configuration file, you need to reload the deamon.
[root@ftosx1 root]# /etc/rc.d/init.d/httpd restart
Stopping httpd:
[ OK ]
Starting httpd:
[ OK ]
[root@ftosx1 root]#
Here is important to know the Document Root that is the directory where is located the Website and also the CGI directory with its respective files.
The CGI directory is defined in ScriptAlias.
Also important is to know the icons, installed in the directory:
[root@ftosx1 icons]# pwd
/var/www/icons
[root@ftosx1 icons]# ls
a.gif
comp.gray.gif icon.sheet.gif
pie2.gif sound1.gif
alert.black.gif compressed.gif
image1.gif pie3.gif
sound2.gif
alert.red.gif continued.gif
image2.gif pie4.gif
sphere1.gif
apache_pb.gif dir.gif
image3.gif pie5.gif
sphere2.gif
back.gif down.gif
index.gif pie6.gif
tar.gif
ball.gray.gif dvi.gif
layout.gif pie7.gif
tex.gif
ball.red.gif f.gif
left.gif pie8.gif
text.gif
binary.gif folder.gif
link.gif portal.gif
transfer.gif
binhex.gif folder.open.gif
mailman.jpg ps.gif
unknown.gif
blank.gif folder.sec.gif
mailman-large.jpg PythonPowered.png up.gif
bomb.gif forward.gif
movie.gif quill.gif
uuencoded.gif
box1.gif generic.gif
patch.gif README
uu.gif
box2.gif generic.red.gif
pdf.gif
right.gif world1.gif
broken.gif generic.sec.gif
p.gif
screw1.gif world2.gif
burst.gif gnu-head-tiny.jpg
php4.gif screw2.gif
c.gif
hand.right.gif pie0.gif
script.gif
comp.blue.gif hand.up.gif
pie1.gif small
[root@ftosx1 icons]#
Each icon corrispond to a extension.
Of course we can create a new image for a new extension.
An Apache module is module to run a specific task.
These modules are Dynamic Shared Objects loaded or readed by the Apache daemon.
For example the PHP programming that we cover in the Chapter 15 PHP Programming is possible using the php module.
The same is valid for the CGI tecnique that we cover in the Chapter 11 CGI Programming
A long all the WebMaster course we cover all the Apache Programming Languages supported as CGI or PHP, as well as HTML.
The respect of the HTML language is intrinsic in the HTTP daemon. All the rest is handled in the configuration file loading its modules.
Apache supports LoadModule and AddModule.
The LoadModule regards the Shared Object, ".so", while the AddModules regards the ".c" files.
The Apache modules are installed in the directory "/etc/httpd/modules/"
The development of an Apache Module will not be covered here.
Apache offers the possibility to create and install multiple WebServers:
For example suppose that you want to run Multiple Servers on your Linux system.
The phone company offers to you a range of IP address.
Working on these address you can order and assign each one to a specific taks or Virtual Host.
For example if you receive the range:
213.82.126.1 ... 213.82.126.23
You can assign the address as follows:
|
![]() |
The previous entries may be created using Alias on the interface. This logical choice allows to assign multiple IP address to the same eth0 card.
From the Apache point of view is necessary to add the following entries in the httpd configuration file:
<VirtualHost 213.82.126.6>
DocumentRoot /mnt/www/YourLinux.org
ServerName www.YourLinux.org
ErrorLog logs/www.YourLinux.org-error_log
CustomLog logs/www.YourLinux.org-access_log
common
</VirtualHost>
<VirtualHost 213.82.126.7>
DocumentRoot /mnt/www/FTLinuxCourse.com
ServerName www.LinuxCourse.org
ErrorLog logs/www.LinuxCourse.org-error_log
CustomLog logs/www.LinuxCourse.org-access_log
common
</VirtualHost>
<VirtualHost 213.82.126.8>
DocumentRoot /mnt/www/MarineLinux.com
ServerName www.MarineLinux.com
ErrorLog logs/www.MarineLinux.org-error_log
CustomLog logs/www.MarineLinux.com-access_log
common
</VirtualHost>
<VirtualHost 213.82.126.9>
DocumentRoot /mnt/www/ThunderLinux.com
ServerName www.ThunderLinux.com
ErrorLog logs/www.ThunderLinux.org-error_log
CustomLog logs/www.ThunderLinux.org-access_log
common
</VirtualHost>
<VirtualHost 213.82.126.12>
DocumentRoot /mnt/www/RPMParadaise.org
ServerName store.futuretg.com
ErrorLog logs/www.rpmparadaise.org.error_log
CustomLog logs/www.rpmparadaise.org.access_log
common
</VirtualHost>
Each directory specified must exist.
At any change the httpd must be reload to take advantage of these new virtual hosts.
Read the answers
to the exercises.
Check the Interactive Exam Cram WebMaster:
Internet Resources for this Chapter.