Installing Apache2

Installing the package

Before we install any packages we should ensure that the correct use-flags are configured so that all required functionality is made available and unnecessary functionality is not included. The www-servers/apache and its dependencies provide a variety of use-flags only some of which will be discussed further here. As usual feel free to add and remove use-flags at will although the minimum set which are required for using this guide in its entirety are shown below.

lisa emerge -pv apache
 
These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild      ] dev-libs/apr-1.3.9  USE="urandom -doc -older-kernels-compatibility"
[ebuild      ] app-admin/eselect-postgresql-0.3
[ebuild      ] dev-db/postgresql-base-8.4.2-r1  USE="nls pam readline ssl zlib -doc -kerberos -ldap -pg_legacytimestamp -threads"
[ebuild      ] virtual/postgresql-base-8.4
[ebuild      ] dev-libs/apr-util-1.3.9  USE="gdbm postgres -berkdb -doc -freetds -ldap -mysql -odbc -sqlite -sqlite3"
[ebuild      ] app-admin/apache-tools-2.2.14  USE="ssl"
[ebuild      ] www-servers/apache-2.2.14-r1  USE="ssl -debug -doc -ldap -static -suexec -threads"
Information:
We have not shown the list of selected APACHE2_MODULES or APACHE2_MPMS as the default will suffice for this guide. Most of the modules are unused however unless mentioned in the relevant section of this guide and can therefore be removed if not required. The default MPM option of prefork is assumed by this guide but can be changed if desired.
 
Caution:
The apache package requires that the kernel be built with SysV IPC support which can be enabled by setting the CONFIG_SYSVIPC variable when configuring your kernel. Failure to enable this option will prevent the apache daemon from functioning correctly.
 

Once you are confident that the correct use-flags are set for the www-servers/apache package, and any dependencies it may require, you can proceed with the installation by issuing the emerge command shown below.

lisa emerge apache

Configuring Apache to use Syslog

The default configuration provided with the www-servers/apache package instructs the apache daemon to write any log messages to a file located at /var/log/apache2/error_log. In a production environment it is often desirable to have all logging performed through a central log service which can be configured to perform a variety of tasks such as sending emails to administrators when certain conditions arise. The apache daemon can be configured to use the standard UNIXsyslog service by modifying the configuration as shown below.

/etc/apache2/modules.d/00_default_settings.conf
ErrorLog /var/log/apache2/error_log
ErrorLog syslog:local1

The default configuration provided with the www-servers/apache package also limits the level of log messages to that of warning, which provides no indication in the logs that the apache is even running. More output can be generated by modifying the LogLevel setting as shown below. We have set the log level to information here which produces plenty of useful output without being as overwhelming as the debug setting. In a production environment the notice log level may be more appropriate.

/etc/apache2/modules.d/00_default_settings.conf
LogLevel warn
LogLevel info

Starting the Apache daemon

When the apache package and its dependencies have finished installing the apache daemon can be started and added to the default run-level using the commands shown below.

lisa /etc/init.d/apache2 start
lisa rc-update add apache2 default

The default configuration for a new installation of apache already provides a set of files to enable serving a single static web site. If you point a web browser at the network address of the host on which you performed the installation you will see that default page. It is a good idea to check that this is indeed the case at this early stage as troubleshooting will only become more difficult as the configuration becomes more complex.

http://web/