Apache is one of the most configurable web servers. It allows you to do virtally everything by changing configuration file.
Please, note that changes do not take immediate effect after saving. Apache must be restarted in order changes take an effect. Before restaring, please, make sure that your changes are valid. You can run apachectl configtest form apache/bin folder to check validity of your new Apache config file (httpd.conf) and make sure that Apache will definitely restart.
The main configuration file of Apache web server is httpd.conf
. It normaly leaves in apache/conf
folder. However, some distributions place it in /etc/apache folder. In order to identify location of Apache config it is better to run locate
command like this:
username@box ~ $ locate httpd.conf
httpd.conf can include other files to make configuration clear and flexible. You can trace includes by looking at httpd.conf.
Apache configuration file (httpd.conf) could be logically divided into several settings sections:
- Overall performance
- Default web site configuration
- Apache modules
- Extensions associations
- Mime types
- Virtual hosts
Overall Performance: the default configuration is pretty well balanced and there is no need to change it unless you have some very specific requirements. In this case you should know what you want and how to archive it. Otherwise, leave it by default.
Default web site configuration: this is only in use in the case when Apache meant to run the only one host on single dedicated IP. This does not happen to often. Running multiple hosts means that Virtual host section settings will override this section. Note, that if you won.t explicitly state some directives in Virtual host section they would be inherited from this section. It is configured well and secure enough for the start. So for most cases you would not need to change any settings here.
Apache modules: this section is used to plug-in external (shared) modules like mod_perl, or PHP. This is a place where you have sometimes manually add line like LoadModule perl_module libexec/libperl.so for including mod_perl or LoadModule php4_module libexec/libphp4.so for enabling PHP4 scripts execution.
To let Apache know that some extension should be parsed by Apache, extension (e.g. .php, .phtm, etc.) should be added to this line DirectoryIndex index.html index.shtml
like that :
DirectoryIndex index.html index.shtml index.php
To make sure that Apache will pass the file with some extension to appropriate module (e.g. PHP) you should state some thing like this:
AddType application/x-httpd-php .php .inc
Mime types: just sets correct mime types. No need to change anything at all.
Virtual hosts: As we already discussed, Apache is configured in the way to server the only one host with dedicated IP by default. However often it is required to run multiple hosts on one server and with one shred IP addres. Here comes the most popular Apache configuration option that usually has to be reconfigured fisrt: Apache Virtual Host. This option allows Apache to serve more then one host / domain.
# First virtual host becomes the default host overriding default host settings above
# This will catch any hostnames not listed, such as:
# localhost, IP address, example.net, example.com, etc.
Redirect permanent / http://www.example.com/
# Canonical host