The latest version of apache is 2.2.6 so just substitute the version number for 2.2.4 in these instructions.
Downloading and unpacking
Unpack the Apache source code via the following commands:-
gunzip httpd-2.2.4.tar.gz tar -xvf httpd-2.2.4.tar
cd into the httpd-2.2.4 directory and start the compilation process:-
To compile apache, type the following:-
./configure --prefix=/usr/local/apache2 \ --enable-rewrite=shared \ --enable-speling=shared
Note that you can continue parameters onto several lines by ending a line with z and then pressing return and entering the next parameter. Alternatively, you can type the whole lot on a single line, just separating each parameter with a space.
make make install
cd srclib/apr ./configure --prefix=/usr/local/apr-httpd/ make make install cd ../apr-util
./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/ make make install cd ../../
Compiling Apache itself
First we want to run configure with all the parameters we require. The ./configure command is entered all on one line.
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/ --enable-rewrite=shared --enable-speling=shared --enable-so make make install cd ..
These notes refer to PHP 4 so you may want to consult my separate php notes for info on PHP 5.
If required, you now want to install PHP via the following commands:-
gunzip php-4.4.7.tar.gz tar -xvf php-4.4.7.tar cd php-4.4.7 ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php.ini make make install
Finally copy the default PHP configuration file to the relevant location, given in the previous ./configure command. Type cp php.ini-dist /etc/php.ini
With a default installation, the Apache configuration files should be inside /usr/local/apache2/conf/
The main configuration file is called httpd.conf and this will need setting up before you can run apache properly.
There are several formats that the main configuration file can be in. Newer versions of Apache have split the main configuration into several files, instead of putting everything into a single, long file. These are known as library files and are generally stored in the extras directory within the main Apache configuration directory.
The easiest method is by way of example. Here's one I did earlier. I've highlighted any changes you may need to do to your version in red. This first example uses the standard method of linking additional configuration files via the library command.
Once you've setup the main configuration file and uncommented the Include conf/extra/httpd-vhosts.conf line, you should now configure the virtualhosts for any domains you wish to host on your server. The virtualhosts configuration is stored within /usr/local/apache2/conf/extras/httpd-vhosts.conf file. Again, here's one I did earlier.
N.B. If an attempt is made to view a domain who's A records point to your server but you've not configured a virtualhost to serve it, Apache will automatically serve the default virtualhost which is the first virtualhost defined in the httpd-vhosts.conf file. For this reason you may want to use the first entry as a dummy 'holding page' website. I tend to use the original Apache htdocs directory for this, which is why this is configured in my example httpd-vhosts.conf file.
Testing and Running Apache
Once you've configured the httpd.conf and httpd-vhosts.conf files, you should test your Apache configuration to ensure that no errors exist in your configuration files. To do this you need to run the Apache binary apachectl which is stored inside /usr/local/apache2/bin/
This can be run from anywhere on the machine, referencing it either by absolute or relative path name. To test the configuration you require a single parameter, configtest, after the command. eg.
As an absolute file reference:-
or a relative file reference from the config directory:-
If all is well you should get an OK message such as the following:-
[root@vhost1 conf]# ../bin/apachectl configtest
You can now start Apache by using the start parameter, eg.
If all is well, Apache should now start running and you should be able to visit your server from a web browser. To perform a quick initial test, enter the IP address of your server in the URL bar of your web browser, eg. http://192.168.1.10 (or whatever the IP address of the machine running apache is).
Click here for an example of what you should see.
To stop apache, simply use the stop parameter. eg.
If you want to stop apache and then automatically restart it, the command is restart
The restart command is probably the best one to use because it will automatically stop it if it's already running then then restart it automatically.
To see if Apache is running ok on your server, you can enter the following ps command:-
ps aux | grep httpd
which will list all the httpd (Apache) processes currently running.
Errors and Problems
If you don't see quite what you expect to see when browsing to your website, the first place you want to look for errors is in the various Apache log files. These are stored in /usr/local/apache2/logs/
There will probably be several log files, two for each virtualhost domain you've configured (see the httpd-vhosts.conf file for the filenames). The two log files stored for each domain are an error file, usually called domainname-error_log and an access log, called domainname-access_log
Understandibly, the error log should contain any errors generated by the domain and the access log will contain a listing of all the visitor accesses to your domain. The error log is the one we're interested in.
If you wish to examine it interactively, which is sometimes easier when you're actually trying to view the page in question from a web browser, then enter the following command from a shell prompt.
tail -f /usr/local/apache2/logs/domain-error_log
Press return a few times in order to get a few blank lines which will make spotting error reports easier. Now attempt to view your web page in a browser window. You should see any errors interactively scroll up the 'tail' listing. Press CTRL-C to exit out when you've seen enough.
If you suspect a problem with your virtualhosts, you may want to try tailing the 'generic' log file too, just in case anything is appearing in that (see my configuration N.B. above).
Apache 2 Frequently Asked Questions (FAQ)
1. Having installed Apache 2, I get the error
1. Having installed Apache 2, I get the error
[Tue Aug 29 13:19:24 2006] [warn] (92)Protocol not available: Failed
to enable APR_TCP_DEFER_ACCEPT
This generally means that your Linux kernel does not support a particular protocol that Apache is trying to enable. This is just a warning message and Apache will fall back to another protocol, so it won't prevent Apache from running.
However, you can remove this error by adding the line
2. I get an error about permissions when trying to start Apache
If you're running Fedora Core it could be that SELinux is enabled, which is preventing access to shared libraries. You need to disable SELinux by entering the following command:-
Alternatively, issue the command
3. I get loads of entries such as "mod_include: Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed" in my error logs.
You should check your httpd.conf configuration file to ensure that each <Directory> directive has +Includes or +IncludesNoExec in its options. If you're unsure, set it to +IncludesNoExec. (see example httpd.conf file, my changes highlighted in red).
4. I get loads of entries such as "GET / HTTP/1.0" 200 1179 "-" "Apache/2.2.3 (Unix) (internal dummy connection)" in my access logs.
This is a way for Apache to signal its children that it's time to die. You probably want to check the MinSpareServers, MaxSpareServers and MacRequestsPerChild settings in the httpd.conf file. The following settings are recommended for a reasonably busy server on the internet.
StartServers 16 MinSpareServers 8 MaxSpareServers 64 MaxClients 256 MaxRequestsPerChild 4000
Links to more information