The Apache web server – Part 1
The Apache web server is a free to use web server and Wikipedia says it is the most popular HTTP server.
A web server works the following way: a user enters an address into the address line of his web browser. This address is called URL (Uniform Resource Locator) and contains two different kinds of information:
1. the address of a computer that has a connection to the internet. This address is also called FQDN (Full Qualified Domain Name)
2. a resource that should be loaded from the server
The core of each Apache web server is httpd (Hypertext Transfer Protocol Daemon). This daemon (a long running background process on the web server) has to return HTTP responses to HTTP requests. Basically this is the only thing that the daemon does. Anyway, we can extend this behavior with modules. The module concept is the main source of the popularity of Apache web server. Modules can be installed and activated. There are many of them. One Example is the php module which enables the server to run php scripts, when a HTTP request comes in.
The installation is quite simple. We only need to install the apache2 packet with our linux packaging tool (for example APT). After this we can check the functionality of apache when we enter the following address into our browser: http://localhost. If everything succeeded, there will be displayed a success message. This site is the default site of our web server. The domain name ‚localhost‘ or the address ‚127.0.0.1‘ are synonyms of our own computer. The Apache web server can be started with the following command: ‚/etc/init.d/apache2 start‘, stopped with ‚/etc/init.d/apache2 stop‘ and restarted with ‚/etc/init.d/apache2 restart‘. For this commands you will need to be root.
The installation was quite easy, but the configuration is more difficult. There exists some configuration files. You can find them in the apache2 directory. The place of this directory is different from distribution to distribution. All informations of this article are based on the Ubuntu distribution:
- httpd.conf: this is the configuration file of the HTTP daemon. There can be global configurations, but normally this file is empty. For the current versions of this web server the apache2.conf file is needed.
- apache2.conf: this is the place for global configurations and this file is well documented.
- envwars: this file has all environment variables of the server.
- ports.conf: here you can define which ports are used by the server. The default is port 80. Port 80 (TCP Port) is typically used for the Hypertext Transfer Protocol (HTTP).
- mods-avaliabl: as said before, the Apache web server uses modules. In this directory you can find all available (installed) modules. Modules can be configured individually.
- mods-enabled: this directory holds all links to configurations of installed and activated modules. Informations an how to configures each module can be found inside the configuration files or in the documentation.
My first website
The Apache2 web server uses so called virtual hosts. With virtual hosts we can run many different sites on one server. It is possible to create different server names for every virtual host. The web server compares these server names with the user requested URL and returns the right site for this server name. If the server name does not exist it is possible to return a default site.
Virtual Hosts can be found in the ’sites-avaliable‘ directory. The host can be defined with a single text file. For the newly installed web server there was already defined a default host, which can be found at the ‚default‘ file in this directory. The elements ‚DocumentRoot‘ and ‚ErrorLog‘ are interesting. Document Root defines the directory that is displayed to the user. That means, that for a request for this host, the ‚index.html‘ file of this directory will be displayed. The Error Log defines a log file that tracks all errors generated by this host. This may be very useful if something does not work as expected.
The first thing we want to do is to name our host. For this we add the line ‚ServerName localhost‘ after the first line. We know, that the root directory of the default host is ‚/var/www‘ so we can change the existing HTML file and replace the content with the following:
<html> <body> <h1>Hallo Welt!</h1> <p>Willkommen auf der neuen Homepage.</p> <br/> <p><a href="phpTest.php">PHP Testseite</a></p> <p><a href="cgi-bin/perlTest.pl">Perl Testeite</a></p> <p><a href="cgi-bin/pythonTest.py">Python Testseite</a></p> </body> </html>
When the file is saved, the browser shows this new file:
The second Part shows you how to configure Apache to work with script languages as well.
I’m a long time watcher and I just thought I’ll drop by and say hello there for your really first time.