This tutorial is for the Apache HTTP web server (Version 1.3 and 2.0). for a list of other web servers for the Hyper Text Transport Protocol.
The Apache configuration file is: /etc/httpd/conf/httpd.conf
Web pages are served from the directory as configured by the DocumentRoot directive. The default directory location is:
- Red Hat 7.x-9, Fedora Core, Red Hat Enterprise 4, CentOS 4: /var/www/html/
- Red Hat 6.x and older: /home/httpd/html/
- Suse 9.x: /srv/www/htdocs/
- Ubuntu (dapper 6.06) / Debian: /var/www/html
The default home page for the default configuration is index.html. Note the pages should not be owned by user apache as this is the process owner of the httpd web server daemon. If the web server process is comprimised, it should not be allowed to alter the files. The files should of course be readable by user apache. Apache may be configured to run as a host for one web site in this fashion or it may be configured to serve for multiple domains. Serving for multiple domains may be achieved in two ways:
- Virtual hosts: One IP address but multiple domains - "Name based" virtual hosting.
- Multiple IP based virtual hosts: One IP address for each domain - "IP based" virtual hosting.
The default configuration will allow one to have multiple user accounts under one domain by using a reference to the user account: http://www.domain.com/~user1/. If no domain is registered or configured, the IP address may also be used: http://XXX.XXX.XXX.XXX/~user1/. [Potential Pitfall] The default umask for directory creation is correct by default but if not use: chmod 755 /home/user1/public_html
[Potential Pitfall] When creating new "Directory" configuration directives, I found that placing them by the existing "Directory" directives to be a bad idea. It would not use the .htaccess file. This was because the statement defining the use of the .htaccess file was after the "Directory" statement. Previously in RH 6.x the files were separated and the order was defined a little different. I now place new "Directory" statements near the end of the file just before the "VirtualHost" statements.
For users of Red Hat 7.1, the GUI configuration tool apacheconf was introduced for the crowd who like to use pretty point and click tools.
Files used by Apache:
- Start/stop/restart script:
- Red Hat/Fedora/CentOS: /etc/rc.d/init.d/httpd
- SuSE 9.3: /etc/init.d/apache2
- Ubuntu (dapper 6.06) / Debian: /etc/init.d/apache2
- Apache main configuration file:
- Red Hat/Fedora/CentOS: /etc/httpd/conf/httpd.conf
- SuSE: /etc/apache2/httpd.conf
(Need to add directive: ServerName host-name) - Ubuntu (dapper 6.06) / Debian: /etc/apache2/apache2.conf
- Apache suplementary configuration files:
- Red Hat/Fedora/CentOS: /etc/httpd/conf.d/component.conf
- SuSE: /etc/apache2/conf.d/component.conf
- Ubuntu (dapper 6.06) / Debian:
- Virtual domains: /etc/apache2/sites-enabled/domain
(Create soft link from /etc/apache2/sites-enabled/domain to /etc/apache2/sites-available/domain to turn on) - Additional configuration directives: /etc/apache2/conf.d/
- Modules to load: /etc/apache2/mods-available/
(Soft link to /etc/apache2/mods-enabled/ to turn on) - Ports to listen to: /etc/apache2/ports.conf
- /var/log/httpd/access_log and error_log - Red Hat/Fedora Core Apache log files
(Suse: /var/log/apache2/)
Start/Stop/Restart scripts: The script is to be run with the qualifiers start, stop, restart or status.
i.e. /etc/rc.d/init.d/httpd restart. A restart allows the web server to start again and read the configuration files to pick up any changes. To have this script invoked upon system boot issue the command chkconfig --add httpd. See Init Process Tutorial for a more complete discussion.
Also Apache control tool: /usr/sbin/apachectl start
Apache Control Command: apachectl:
Red Hat / Fedora Core / CentOS: apachectl directive
Ubuntu dapper 6.06 / Debian: apache2ctl directive Directive | Description |
start | Start the Apache httpd daemon. Gives an error if it is already running. |
stop | Stops the Apache httpd daemon. |
graceful | Gracefully restarts the Apache httpd daemon. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. |
restart | Restarts the Apache httpd daemon. If the daemon is not running, it is started. This command automatically checks the configuration files as in configtest before initiating the restart to make sure the daemon doesn't die. |
status | Displays a brief status report. |
fullstatus | Displays a full status report from mod_status. Requires mod_status enabled on your server and a text-based browser such as lynx available on your system. The URL used to access the status report can be set by editing the STATUSURL variable in the script. |
configtest -t | Run a configuration file syntax test. |