We can either use prebuilt apache package or download the source code and build the server with all the modules we need. The difference between the two approaches is the version of the Apache we end up using (the latest available version of the Apache is not necessarily available from Fedora repository) and the directives the package will be installed. In this lab we will use the source code installation but I also recommend you to use the other approach to feel the difference.
Please down load the source code of the latest version of the Apache server. At the time of writing the latest is version 2.2.8 and it's available from the Apache web site. Traditionally, the source code is downloaded and compiled in /usr/local/src directory. Run the following command to get the source code and unpack it:
# mkdir /usr/local/src # cd /usr/local/src # wget http://apache.mirrors.timporter.net/httpd/httpd-2.2.8.tar.gz # tar xvfz httpd-2.2.8.tar.gz # cd httpd-2.2.8
If all commands executed successfully, you find yourself in the directory where the source code for Apache. It is not a bad idea to start building your own Apache server from reading README and INSTALL text files. If you have read those or decided to ignore the hint, you are ready to compile.
Usually, compilation process consists of two steps: configuration and actual compilation. The purpose of configuration is to build the Makefile that will contain all the instruction for correct compilation your own version of Apache. Thus, the configuration is actually more important step. The configuration is done by running the configure script located here in the directory you are currently in. Running the script with no arguments mean that you leave all the default setting intact. If you want to change something, you need to use some options. Please run
# ./configure --help | lessto read the list of all available version with short description. Currently, we will use the following commands to configure and build the server:
# ./configure --prefix=/usr/local/apache-2.2.8 --htmldir=/data/www --enable-userdir --enable-info # makeOnce compilation process finished, we are ready to install it:
# make installIf the command successfully completed, you just installed the Apache server.
Apache installation contains special script to start and stop apache service. Please run
# cp /usr/local/apache-2.2.8/bin/apachectl /etc/init.d/to copy this script into the standard location for all startup scripts. Now, go to the /etc/init.d directory. To start the server, you can use
# ./apachectl startor
# service apachectl startIf you want to make this script automatically start every time you boot your system, add the following lines to the script file
# chkconfig: 2345 92 18 # description: Apache web server v 2.2.8and run the chkconfig command
# chkconfig --add apachectl # chkconfig --list apachectl
All Apache configuration instructions are located in the httpd.conf file. The exact location of the file depends on the way you installed the package and the options you used to build it. In the described scenario, the file will be located in /usr/local/apache-2.2.8/conf directory. Note: that this file is read only at the moment when the server starts. So, if you edit some settings, you need to restart the server for the settings to take affect.
Editing the settings in the file please do the following:
User apache Group apache
| Feature | Description |
|---|---|
| ExecCGI | The execution of CGI scripts is permitted. |
| FollowSymLinks | The server will traverse symbolic links. |
| Includes | Server-side includes are permitted. |
| IncludeNOEXEC | Server-side includes are permitted, except #exec element. |
| Indexes | If none of the files specified in the DirectoryIndex directive exists, a directory index will be generated by mod_autoindex. |
| MultiViews | The server allows content negotiation based on preferences from the user's browser, such as preferred language, character set, and media type. |
| SymLinksIfOwnerMatch | The server will traverse symbolic links only if the owner of the target is the same as the owner of the link. |
| None | None of the features above are enabled. |
| All | All of the features above are enabled, with the exception of MultiViews. This must be explicitly enabled. |
AllowOverride directive instructs the server which features can be overridden in .htaccess file.
| Feature | Description |
|---|---|
| AuthConfig | Enables authentication-related directives (AuthName, AuthType, AuthUserFile, AuthGroupFile, Require, and so on). |
| FileInfo | Enables MIME-related directives (AddType, AddEncoding, AddLanguage, LanguagePriority, and so on). |
| Indexes | Enables directives related to directory indexing (FancyIndexing, DirectoryIndex, IndexOptions, IndexIgnore, HeaderName, ReadmeName, AddIcon, Add). |
| Limit | Enables directives controlling host access (Allow, Deny, and Order). |
| Options | Enables the Options directive. |
| None | None of the access features above can be overridden. |
| All | All the access features above can be overridden. |
<Directory "/var/www">
Options Indexes FollowSymLinks
AllowOverride AuthConfig Limit
Order allow,deny
Allow from all
</Directory>
#ErrorDocument 404 /missing.htmlin the Apache configuration file.
#Include extra/httpd-userdir.confand then in the extra/httpd-userdir.conf change the public_html directory to www directory. Note: do not forget to edit the <Directory> directive as well.
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
Restart the server and access http://localhost/server-status/. .
Now, add the line
ExtendedStatus Onand compare the results.
<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
and access http://localhost/server-info/
#! /bin/bash echo -e "Content-type: text/html\n\n" myname=`whoami` echo "<h3>Hello! User $myname welcomes you on his web page</h3>"Do not forget to make this file executable.
AddHandler cgi-script .cgi
Please install and play with the following tools: