Chapter W17. Apache Configuration
 
Goals for this chapter: rpm packages covered in this chapter: 
  • httpd (apache)
 
   
Documentation is the castor oil of programmig. 
Managers know it must be good because the programmers hate it so much.
-- Anonymous
What is Apache?

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 configuration file

The Apache httpd daemon haves a configuration file called: httpd.conf.

In this files are present all the

After the installation, Apache may runs or not. On FTOSX 2001, Apache runs after the installation. To start Apache on RedHat we need to run "ntsysv" and choose "httpd"

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.

Apache Modules

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.
 

Configuring Virtual hosts

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:

  • 213.82.126.1 -> router
  • 213.82.126.2 -> First Virtual Host
  • 213.82.126.3 -> Second ...
  • ...
  • 213.82.126.6 -> 

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.

Exercises

  1. Check is apache is running on your system.
  2. Restart apache daemon.
  3. Locate Apache Configuration file, change WebServer Root dir and reload it.
Tests
  1. What is the name of the Apache daemon on Linux ?
  2. Where are installed the Apache icons ?
  3. What is the command to reload the Apache configuration ?
  4. What is an Apache module ?
  5. Is  the PHP programming possible using an Apache module ?
  6. Is the PERL programming language possible using an Apache module ?
  7. Is the CGI programming technique possible using an Apache module ?
  8. What is the difference between "Load Module" and "Add Module" ?
  9. Where are located the Apache Modules ?
  10. Where are located the log files ?
  11. Is possible to change the format of a log file ?


Read the answers to the exercises.
Check the Interactive Exam Cram WebMaster: Try the interactive cram ...

Internet Resources for this Chapter.