Apache/ru

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

Global support
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:

Конфигурационные файлы
There are two main files that configure Apache2's behavior on the system:


 * Конфигурационный файл сценария инициализации Apache2 в Gentoo:


 * Стандартный файл конфигурации сервера Apache2:

apache2
The file located in  is Gentoo's init script configuration file. The only active line in this file is the  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.

httpd.conf
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   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.

Настройки по умолчанию
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.

Первые признаки жизни
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
Control this module by editing and  files, then restart Apache.

Включение поддержки PHP
Установите PHP с USE-флагом  и включите соответствующий модуль:

Перед тем как проверить, работает ли модуль PHP, убедитесь, что файл существует и содержит следующее определение:

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: http://localhost/

A table describing the PHP settings should be visible.

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 chown like in the following example:

Ниже приведены два примера определения виртуальных хостов, один для domainname1.com, а второй для domainname2.com. Обратите внимание, что директивы  и   различаются, хотя сам хост  один и тот же:

Также рекомендуется дать определение виртуального хоста на основании IP. Это позволит администратору оставить сообщение пользователям, которые пытаются зайти на сайт по IP-адресу:

После добавления новых хостов сервер нужно (мягко) перезапустить, чтобы новые сайты стали активны.

Включение PHP через fcgid
Установите и. Пакет PHP требует включения USE-флага :

Отредактируйте файл :

Создайте необходимые каталоги:

Сделайте символическую ссылку для PHP-wrapper:

Включите модуль fcgid:

В конце перезапустите Apache и проверьте сайт, который мы создали раньше. Значение  должно быть CGI/FastCGI

Включение PHP-FPM через mod_proxy_fcgi в Apache 2.4
PHP, начиная с версии 5.3, поддерживает дополнительный режим — FastCGI Process Manager или FPM.

The following method relies on the FilesMatch directive and be placed within the main server config or VirtualHosts. The location of the UNIX socket is determined by the listen directive in the, allowing for specifying separate pools per site or function.

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

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

Next, update the file as follows:

Затем подключите модули PHP и proxy:

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:

Смотрите также

 * Lighttpd - A fast, lightweight web server.
 * Nginx - A small, robust, and high-performance HTTP server and reverse proxy.

Внешние ресурсы

 * статья Slicehost: Установка Apache в Gentoo
 * статья Slicehost: Конфигурационые файлы Apache в Gentoo
 * статья Slicehost: Настройка Apache MPM в Gentoo
 * статья Slicehost: Настройка Apache в Gentoo
 * статья Slicehost: Виртуальные хосты Apache в Gentoo
 * статья Slicehost: Включение и использование модуля apache mod_status в Gentoo
 * документация apache.org
 * Apache2 mod_pagespeed