Apache/it

The Apache HTTP Server is an efficient, extensible web server. It is one of the most popular web servers used the Internet.

Emerge
If you want to use the Apache event MPM, then add the following to make.conf:

If you want to use the Apache worker MPM, then add the following to make.conf:

And, enable the Apache threads USE flag:

Then emerge Apache:

Supporto globale
Enabling the  global USE flag provides support for Apache in other packages. This may cause to be installed automatically if a package depending on Apache has been emerged.

After configuring USE variables, update the system so the changes take effect:

Files
There are two main files that configure Apache2's behavior on the system:


 * Gentoo's Apache2 init script configuration file


 * Apache2 server's conventional configuration file

The file located in  is Gentoo's init script configuration file. The only active line in this file is the APACHE2_OPTS variable line:

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.

Primi segni di vita
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
Install :

Enable the  module in the  file's APACHE2_OPTS variable:

Control this module by editing and  files, then restart Apache.

Abilitazione supporto PHP
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:

Di seguito due esempi di definizione di Virtual Host, uno per domainname1.com ed uno per domainname2.com. Da notare le differenti direttive  e   anche se l'host in sè  rimane invariato

E'raccomandato anche definire un virtual host IP based. Questo permette all'amministratore di mettere messaggi per quegli utenti che cercano di raggiungere il sito attraverso il suo indirizzo IP:

Dopo aver inserito i virtual hosts, affinchè questi divention attivi il server deve essere restartato (anche con graceful).

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

Editare il file :

Create le directory necessarie:

Creare un link simbolico per il wrapper PHP:

Enable the  module:

Alla fine, riavviare Apache e controllare il sito  creato precedentemente. Il valore di  dovrebbe essere CGI/FastCGI

Abilitare PHP-FPM attraverso il 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:

OpenRC
Avviare il server Apache:

Aggiungere Apache al runlevel default:

Riavviare il servizio Apache:

Ricaricare i file di configurazione:

systemd
Avviare il server Apache:

Aggiungere Apache al runlevel default:

Riavviare il servizio Apache:

Risorse
Il server Apache può essere difficoltoso da configurare. Di seguito alcune risorse utili in caso di problemi:


 * Guida al Troubleshooting

Testare
Verificare quali siano le interfaccie IP e le porte sulle quali il server Apache attivo è in ascolto:

Testare se una connessione verso un server Apache funziona in localhost:

Interrompere la connessione con + e.

Errore "apr_sockaddr_info_get failed for "
Errore:

apache2: apr_sockaddr_info_get failed for System_Hostname

Risoluzione:

Quando questo succede, aggiungete il vostro hostname al file

Vedere anche

 * Lighttpd - un web server leggero e veloce.
 * Nginx - un HTTP server piccolo, robusto e ad alte prestazioni, con funzionalità Reverse Proxy

Risorse esterne

 * 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