Apache

The Apache HTTP Server is a efficient and extensible web server and the most popular on the Internet.

Support in other packages
There is a global USE flag apache2 which enables support for Apache in other packages. This may cause to be pulled in automatically if such packages are used.

After setting this you want to update your system so the changes take effect:

Launching and restarting
Start the Apache server:

Add Apache to the default runlevel:

Restart the Apache service:

Testing
Verifying IP interfaces and ports on which apache2 is running on and listening to:

Testing if a connection to a Apache server is working on localhost:

Interrupt the connection test with + and.

Configuration files
Apache server's configuration in Gentoo is somewhat different from others distribution and this deserves some explanations. There are 2 main files that preside to this configuration.
 * Gentoo's own apache2 configuration file
 * Apache server's conventionnal configuration file

Gentoo's own configuration file
The only active line in this file is as follow :

This line defines options that will be interpreted by the various configuration files using the   statement to activate or deactivate some part of the whole configuration. We will come back to this where appropriate in the rest of this guide.

Apache server's conventionnal configuration file httpd.conf
In fact this file is only an entry point as the whole configuration is splitted in many files in the directory, that are assembled  together using the Include directive. For example, the statement Include /etc/apache2/modules.d/*.conf, in httpd.conf, aims at including all the files in which name ends with .conf.

Taking into account what has been said in the subsection above, and as module configuration files (files in /etc/apache2/modules.d) almost always start with the , the content of one file inside, will ONLY be assembled with the rest of the configuration, if the matching option is set using a -D module-name flag in the APACHE2_OPTS variable in the file. The configuration file is an exception to this rule as it doesn't start with an IfDefine statement and therefore is always included in the resulting configuration.

Default configuration
After a fresh install of apache server, the configuration resulting from the assemblage of the different configuration files is as follow. We start with the entry point /etc/apache2/httpd.conf and add the included parts with a comment stating it in an obvious manner.

First sign of life
As you can see in the initial configuration above, the pre-installed virtual host's DocumentRoot  directory is, its server name is localhost. In addition an index.htlm file is provided in the DocumentRoot directory, thus to ckeck whether all is correctly installed or not, point your browser on http://www.localhost. You should see an " It works !" message on the page.

Enabling PHP support
Install PHP with the apache2 USE flag and enable the module:

To test if the PHP module works, create a test page:

Now open the test page: http://localhost/. You should see a table describing the PHP settings

Adding your own virtual hosts
For each virtual host, provide a DocumentRoot directory that is made accessible to the apache server, add a myVirtualHost.conf file in directory and don't forget to add an entry for your domain name in.

Troubleshooting

 * Troubleshooting guide

External resources

 * Slicehost article: Installing Apache on Gentoo
 * Slicehost article: Apache configuration files on Gentoo
 * Slicehost article: Configuring the Apache MPM on Gentoo
 * Slicehost article: Apache configuration on Gentoo
 * Slicehost article: Apache Virtual Hosts on Gentoo
 * Slicehost article: Enabling and using apache's mod_status on Gentoo
 * apache.org documentation
 * Apache2 mod_pagespeed