Apache/nl

De Apache HTTP-server is webserver. Het is een van de populairste webservers op het internet.]]

Multi-Processing Module
If you want to use the Apache event or worker MPM, enable the Apache threads USE flag:

Wanneer u de Apache-event MPM wilt gebruiken, voeg het volgende toe aan make.conf:

Wanneer u de Apache-worker MPM wilt gebruiken, voeg het volgende toe aan make.conf:

If no Multi-Processing Module (MPM) is selected, the default MPM is used. The default MPM depends on platform capabilities (like threads support), read more in the official Apache docs.

Installeer tenslotte Apache:

Systeembrede activering
Het systeembreed activeren van de  USE -vlag geeft ondersteuning voor Apache in andere pakketten. Dit kan zorgen dat automatisch wordt geïnstalleerd wanneer een pakket dat afhankelijk is van Apache geïnstalleerd wordt.

Na het configureren van de USE -vlaggen moet het systeem geupdated worden.

Bestanden
Er zijn twee configuratie-bestanden die het grootste deel van Apache2's gedrag op het systeem bepalen.


 * Gentoo's Apache2 init script configuratie-bestand


 * Het configuratie-bestand van Apache2 zelf:

Gentoo's initscript configuratie-bestand is in de map. De enige regel met een betekenis in dit bestand is de regele met de APACHE2_OPTS variabele:

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. This will be returned to later in the article.

The file is Apache server's conventional configuration file. In fact this file is only an entry point for configuration. The whole configuration is split in many files in the directory, that are assembled together using the   directive. For example, the statement, in , aims at including all the files in  which name ends with.

Taking into account what has been said in the subsection above, and as module configuration files (files in ) 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   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   statement and therefore is always included in the resulting configuration.

Defaults
After a fresh install of an Apache server, the configuration resulting from the assemblage of the different configuration files is as follows. Start with the entry point.

First sign of life
As visible in the initial configuration above, the pre-installed virtual host's   directory is, its server name is localhost. In addition an index.html file is provided in the  directory, thus to check whether everything is correctly installed or not, point a browser to http://localhost/.

An "It works!" message should be printed on the page.

Enabling mod_security
ModSecurity is a rule-based web application firewall that monitors web service traffic, to block attacks exploiting known vulnerabilities.

Install :

Enable the  module in the  file's APACHE2_OPTS variable:

Control this module by editing and  files. The file contains the recommended configuration https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#A_Recommended_Base_Configuration. Copy the basic configuration to the and tweak the settings according to your needs. Unpack the file to a suitable location, e.g., tweak it, and include the unpacked file in. Finally, restart Apache. Look for the errors in the Apache log files of your sites and act accordingly.

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

Before testing if the PHP module works, check that the file exists and contains the following definition:

If it does not exist create it.

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

Now, suppress or rename and open the test page:

A table describing the PHP settings should be visible.

Modify PHP versions
To change the version of PHP handled by Apache, first list the available versions for the  Server Application Programming Interface (SAPI):

Change it to the version of choice:

Substitute  in the example above to the requested number in the output of  as displayed earlier on.

Virtual hosts
For each virtual host, provide a  directory that is reachable and accessible by the Apache daemon. Add a virtual host configuration file in the  directory which uses this   and the virtual host server name. Do not forget to add an entry for this domain name in.

To assign the apache user/group ownership on the virtual host files, use like in the following example:

Below are two example virtual host definitions, one for domainname1.com and one for domainname2.com. Notice the different  and   directives even though the host itself  remains the same:

It is recommended to provide an IP based virtual host definition as well. This allows the administrator to put up a message for users that try to reach a site through its IP address:

After inserting virtual hosts, the server needs to be (gracefully) restarted for the new sites to become active.

Enabling PHP through fcgid
Install and. The PHP package requires  to be set as a USE flag:

Edit the file:

Create the needed directory:

Symlink it for the PHP wrapper:

Enable the  module:

Finally restart Apache and check the  site created earlier. The value of  should be CGI/FastCGI

Enabling PHP-FPM through mod_proxy_fcgi in Apache 2.4
The following pre-requisites must be satisfied to enable PHP-FPM through mod_proxy_fcgi:
 * >= PHP 5.3
 * >= Apache 2.4

Furthermore, there are a few restrictions on the availability of functionality within Apache 2.4:
 * >= Apache 2.4.9, if you want to communicate with PHP-FPM over UNIX sockets
 * >= Apache 2.4.10, if you want to use SetHandler instead of ProxyPassMatch.

The following configuration will only work with Apache 2.4.10 and newer. It relies on the  directive and be placed within the main server config or. The location of the UNIX socket is determined by the  directive in the  configuration file, allowing for specifying separate pools per site or function.

In the following example,  is placed within the PHP module config file of Apache:

Or, you can use ProxPassMatch -- the only option if the Apache version is between 2.4.0 and 2.4.8, inclusive.

By default the  directive is not set to a socket. First create the directory for the socket file:

Next, update the file as follows:

Then enable both the  and   modules:

Web frameworks and Apache
Some of the web frameworks that can work with Apache are covered on the wiki:


 * Rails
 * Django

HTTPS with TLS certificates from Let’s Encrypt
It is important that any public-facing web server provide "secure" HTTPS access. Often, sites providing HTTPS will be configured to redirect HTTP requests to the HTTPS equivalent URL.

Let’s Encrypt is a not-for-profit certificate authority that issues free TLS certificats. is a utility available in the Gentoo repository for easily requesting and installing TLS certificates, and automatically setting up HTTPS access for Apache.

See the Let’s Encrypt article for information about using. The EFF also have specific instructions on using on Gentoo to configure Apache.

OpenRC
Start the Apache server:

Add Apache to the default runlevel:

Restart the Apache service:

Reload Apache configuration files:

systemd
Start the Apache server:

Add Apache to the default runlevel:

Restart the Apache service:

Resources
The Apache server can be difficult to configure properly. Below are some resources that may be helpful when issues occur:


 * Troubleshooting guide

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.

apr_sockaddr_info_get failed for 
Error:

apache2: apr_sockaddr_info_get failed for System_Hostname

Resolution:

When this occurs, add the host name to the file:

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