Beginners Start Here!

Introduction

So you have downloaded Apache for your OS. Where do you install it? Some suggestions for Unix users are:
  • /var/apache
  • /var/www
  • /home/www
  • /usr/www
The choice is yours. For security reasons, don't install it in / or in /etc. If you do, you could make a mistake in the configuring Apache and allow access to your system configuration files.

Deciding where to locate Apache and its configuration files is still a problem if you are installing Apache from the source code.

If you are using pre-build RPM's, DEB's.....then where to locate it is already decided for you.

Apache httpd binary location(s)
/usr/local/apache2/bin     Apache "classic" (default)
/usr/local/{s}bin     GNU/FreeBSD
/usr/{s}bin     Mac/RedHat/SuSE/OpenBSD/Debian
/opt/apache/{s}bin     /opt file system layout
/bin     BeOS
/usr/contrib/bin     BSDI BSD/OS
/usr/apache/bin     Solaris

Once the binary has been located, it is relatively easy to locate the remaining components we need access to to configure and run Apache.

	httpd [ -d  serverroot ] [ -f config ] [ -C directive ] 
	[ -c  directive ] [ -D parameter ] [ -e level ] [ -E  file ] 
	[ -k start|restart|graceful|stop ] [ -R directory ] [ -h ] 
	[ -l ] [ -L ] [ -S ] [ -t ] [ -v ] [ -V ] [ -X ]

The -V option prints the compile options, two of which are HTTPD_ROOT and SERVER_CONFIG_FILE, which allow us to locate the Apache configuration files.

The NT distribution defaults to c:\Program Files\Apache You should override this default and install it in C:\Apache. Why? If you want to run Apache as an NT service you need to install in c:\Apache (see Apache Week). Running it as a NT service lets us start and stop apache with the control panel.

Prerequisites

To run Apache on your system you have to have installed TCP/IP. Don't even think about proceeding any further until you have completed this installation. The installation of the TCP/IP protocol on your system is outside the scope of this document. Check you system manuals for instructions.

Gosh! Back in the bad old days when I first created the RTFM, TCP/IP was an option. I don't know of any OS that doesn't include it now.

Once TCP/IP is running, you need to determine either:

  • The IP address of you machine or
  • The DNS name
Again, check your system manuals to determine this information. You will need this information to complete the initial configuration of Apache.

Initial Configuration

Now that it's been installed somewhere on your system, you need to do some configuration before trying to start Apache. Get out your favorite text editor, and edit the httd.conf file in the .../apache/conf directory. You need to change the following lines:

Before version 1.3.3, there were three configuration files, srm.conf, access.conf, and httpd.conf. Three separate configuration files were difficult to justify, particularly when there was a large overlap of information between them. By version 1.3.3 the configuration information was officially combined into a single file (httpd.conf) but beware some distributions still use multiple files. The release notes for both version 2.0 and 2.2 have notes regarding "simplified configuration". Different solutions to "simplified configuration" are reached, depending on which Linux distribution and/or build configuration is used. Some distributions, such as Red Hat, continue to use a single configuration file, targeted a running a single instance, non-virtualized web server. In contrast, Ubuntu has opted to use virtual hosts in the initial configuration and separate configuration directives into logical gropings, with separate sub-directories for these directives.

Which configuration layout is better is very subjective. With the Red Hat style of configuration, everything is in one file. If you need to run a second web server on the same machine, examples of the virtual hosting directives are included as comments in this file. In contrast, the Ubuntu style of configuration layout can lead to a bit of a treasure hunt when trying to locate which file contains a particular directive. In favour of this style, is the relatively clean separation of functionality into separate files and directories and a "README" file that provides broad hints as to where functionality can be found. Both Red Hat (Fedora FC5) and Ubuntu (Dapper Drake 6.06) have configuration files with default settings for serving static html and running cgi-bin applications. The Ubuntu virtual host configuration is more comprehensive when compared to the example configuration provided by Fedora as Ubuntu includes all the settings for cgi-bin application in its virtual hosting configuration.



From:
 
# ServerRoot: The directory the server's config, error, and log files
# are kept in

ServerRoot "@@ServerRoot@@"
  To:  
# ServerRoot: The directory the server's config, error, and log files
# are kept in

ServerRoot "/var/apache"
  If you installed Apache in /var/apache. ServerRoot should be set to the directory where you installed Apache.

In the case of NT change ServerRoot to:

 
# ServerRoot: The directory the server's config, error, and log files
# are kept in

ServerRoot "c:/apache"
 

The only other change required it to set the ServerName or the BindAddress. If you have a valid DNS name for your server, change:

 
# ServerName allows you to set a host name which is sent back to clients for
# your server if it's different than the one the program would get (i.e. use
# "www" instead of the host's real name).
#
# Note: You cannot just invent host names and hope they work. The name you 
# define here must be a valid DNS name for your host. If you don't understand
# this, ask your network administrator.

#ServerName new.host.name
 

To:

 
# ServerName allows you to set a host name which is sent back to clients for
# your server if it's different than the one the program would get (i.e. use
# "www" instead of the host's real name).
#
# Note: You cannot just invent host names and hope they work. The name you 
# define here must be a valid DNS name for your host. If you don't understand
# this, ask your network administrator.

ServerName www3.jlk.net
 

You should use your own DNS name in place of www3.jlk.net

If you only have an IP address, you need to set BindAddress from:

 
# BindAddress: You can support virtual hosts with this option. This option
# is used to tell the server which IP address to listen to. It can either
# contain "*", an IP address, or a fully qualified Internet domain name.
# See also the VirtualHost directive.

#BindAddress *
  To:  
# BindAddress: You can support virtual hosts with this option. This option
# is used to tell the server which IP address to listen to. It can either
# contain "*", an IP address, or a fully qualified Internet domain name.
# See also the VirtualHost directive.

BindAddress 194.70.74.8
  You should change 194.70.74.8 to your own IP address. Save the file and exit your editor.

Finally you need to configure the location for your html documents. Edit srm.conf and change:

 
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.

DocumentRoot "@@ServerRoot@@/htdocs"
  To:  
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.

DocumentRoot "c:/apache/htdocs"
  The above example, it for NT. Unix users would, for example change DocumentRoot to /var/apache/htdocs. Save the file and exit your editor.

Starting Apache

A summary of the startup options is included in your documentation for from the Apache web site. The -d option is only one we need at this time.

Example: If we have installed Apache in /var/apache the the command line to start the server is:

 
/var/apache/bin -d /var/apache
  Any problems should show up as error messages when you try to start Apache. Unix users should note, that you must be "root" Uid=0 to run Apache with this default configuration since Apache attempts to bind to Port 80, the default httpd protocol port. If you are "root" you will need to change the Port option in your httpd.conf file to a number which is greater than 1023.  
# Port: The port the standalone listens to.

Port 8080
  If you do need to change the Port, the URL for you top level page will need to include the port number in it. Example: if www.jlk.net were running with the above Port configuration, the URL would be:  
http://www.jlk/net:8080
 

NT users need to start Apache with the -i option. Open a dos box, change directories to c:\apache;

 
apache -i
  You will then be able to start and stop Apache from the Services element of the Control Panel.

 
 
Note: Each time you make a change to any of the configuration files, you must get Apache to re-read them. Unix users can accomplish this with the -HUP signal.
 
# cat /var/run/httpd.pid
252
# kill -HUP 252
# tail /var/log/httpd/error_log
     .
     .
     .
     .
[Sun Apr  5 12:09:18 1998] SIGHUP received.  Attempting to restart
[Sun Apr  5 12:09:18 1998] Server configured -- resuming normal operations 
#
  On NT, you will have to stop and re-start Apache with the control pannel. On the current 1.3b3 release, Apache can take several minutes to stop. Therefore. during development, you might want to consider running Apache from a dos box as it is quicker to shutdown and restart. Your mileage may vary.

References

General

Apache Directives

Other Option

There is one option should set when beginning to configure Apache. You should add the e-mail address of the person responsible for the configuration of your server. When certain error occur when a page is request, Apache may inform the browser, with a default error message. Generally this occurs when you have a link to a page which does not exist. The e-mail address of your administrator will be displayed in the error message. You should configure this persons e-mail address with the ServerAdmin option.
 
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.

ServerAdmin you@your.address
  By default your access and error log files and the Apache process id live in the .../apache/logs directory. Some operating systems such as BSDI have a central repository of system log files or system process ids. You can control where your log files and the Apache process id are stored with the following directives.  
# ErrorLog: The location of the error log file. If this does not start
# with /, ServerRoot is prepended to it.

ErrorLog logs/error_log

# TransferLog: The location of the transfer log file. If this does not
# start with /, ServerRoot is prepended to it.

TransferLog logs/access_log

# PidFile: The file the server should log its pid to
PidFile logs/httpd.pid
 

References

 


RTFM Index
Tell us what you think!
Copyright © 2006 Open Source Migrations ltd. All Rights Reserved.
Apache RTFM last updated Saturday October 21 2006