Apache Quickstart HOWTO

From openSUSE

This document describes how to get your server up and running as fast as possible. It is not an extensive introduction into web servers, just a quick step-by-step reference.


Contents

General machine setup:

  • configure your network
  • make sure that all components are current, by running YaST Online Update regularly

Synchronise time

parts of the HTTP protocol depend on correct time.

  • configure machine as NTP client, either with the YaST configuration module or by editing /etc/ntp.conf (just put a server name into it) and starting "rcntpd start", and running "chkconfig -a ntpd"

Firewall

  • if you run a firewall, make sure to allow access through port 80 if the server should be reachable from other machines.

Start the server, and configure it to automatically start at boot time:

  • rcapache2 start
  • chkconfig -a apache2

Add web pages:

  • the default DocumentRoot is at /srv/www/htdocs
  • if you add documents somewhere else and link to them with e.g. Alias someplace "/path/to/someplace" make sure to also use <Directory /path/to/someplace> ... </Directory> to define access permissions and options for that directory, since (starting with SuSE Linux 9.0) access to the entire filesystem is blocked by default. See http://httpd.apache.org/docs-2.2/mod/core.html#directory

Go through /etc/sysconfig/apache2:

  • check loaded modules (APACHE_MODULES="..."). (Can also be seen with the command "a2enmod -l".)
  • add "php5", "perl", or other needed modules to APACHE_MODULES al gusto. Modules can be enabled/disabled in a simple (Debian-compatible ;) way from the command line like this:
a2enmod php5
a2dismod php5
  • there is also a command a2enflag, to change APACHE_SERVER_FLAGS
  • restart the server ('rcapache2 restart')

Where to add your own configuration:

  • add e.g. /etc/apache2/httpd.conf.local and change APACHE_CONF_INCLUDE_FILES in /etc/sysconfig/apache2, e.g. APACHE_CONF_INCLUDE_FILES="httpd.conf.local"
  • to understand the hierarchy and layout of all include files, read the comments at the top of httpd.conf
  • if you strongly prefer the old, single, 40K, monolithic configuration file, it's there! Just use it:
# mv /etc/apache2/httpd.conf /etc/apache2/httpd.conf.dist                                                                                                                                                                                 
# cp /usr/share/doc/packages/apache2/httpd-std.conf-prefork /etc/apache2/httpd.conf                                                                                                                                                       
# rcapache2 restart

Add virtual hosts:

see here http://httpd.apache.org/docs/2.2/vhosts/name-based.html

  • edit /etc/apache2/listen.conf. It is a suitable place to add NameVirtualHost directives.
  • copy the commented template /etc/apache2/vhosts.d/vhost.template to /etc/apache2/vhosts.d/yourhost.conf
  • edit /etc/apache2/vhosts.d/yourhost.conf to suit your needs
  • alternative approach: simply append the NameVirtualHost directive and the <VirtualHost> container to your single local configuration file, if you have one (like httpd.conf.local, as described above)
  • if in doubt about how apache interprets your vhost setup, always use httpd2 -S. If SSL is involved you will need to run httpd2 -S -DSSL instead -- likewise for other needed defines.
  • the "default" server, which responds to requests not handled by other vhosts, is always the one which is defined first. If you want a dedicated "default" server for such requests, you need to put it first in the configuration. Consequently, if the configuration is in multiple files, like /etc/apache2/vhosts.d/*.conf, then simply name it _default.conf, or e.g. _192.168.0.1.conf if you do it per IP address. Then it is read first.

TROUBLESHOOTING -- if all does not work:

  • fire up "tail -F /var/log/apache2/*_log &" in a root shell
  • reproduce what is not working (by starting apache, doing client requests, or whatever), and see how it is reflected in the logs
  • if you suspect a bug, please make use of https://bugzilla.novell.com

To learn more about configuration

building 3rd party modules:

  • install apache2-devel (and of course gcc as well as other needed development tools)
  • use one of the following:
apxs2          -- to build a module for all MPM types, or
apxs2-prefork  -- to build a module for the Prefork MPM, or
apxs2-worker   -- to build a module for the Worker MPM

(see man 8 apxs2). In most cases you can just use "apxs2", the most notably exception being mod_php4. Using apxs2-prefork then will prevent you from accidentally trying to use the module with the Worker MPM. Also, very few modules need to know interna from the MPMs, trying to include mpm.h and they will need to be built with apxs2-<mpmname>.

Typical example:

# apxs2 -c -i -a mod_foo.c                                                                                                                                                                                                                
-c does compile the module
-i installs it in the right place
-a activates it by running 'a2enmod mod_foo'
  • if the module's build system does not allow to use apxs, use at least CFLAGS=$(apxs2 -q CFLAGS) to determine the right compiler flags for your apache installation.

See Also

  • Apache more HOWTOs about Apache web server

External Links