Apache/ja

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

グローバルなサポート
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
システム上のApache2の動作を設定する、2つの主要なファイルがあります:


 * 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.

稼働の第一歩
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.

PHP サポートを有効にする
Install PHP with the  USE flag and enable the module:

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:

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 eselect php list apache2 as displayed earlier on.

バーチャルホスト
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:

以下に、2つのバーチャルホスト定義例があります. 1つは domainname1.com で、もう1つは domainname2.com です. 本来のホスト自体（ ）は同じでも、 と  のディレクティブがそれぞれ異なります.

IPアドレスベースのバーチャルホスト定義を行うこともまた推奨されています. 管理者はユーザに対して、IPアドレスを通じてサイトへアクセスさせメッセージを掲げられます.

バーチャルホストを挿入したあとには、新たなウェブサイトを有効にするために、ウェブサーバを（完全に）再起動する必要があります.

fcgid 経由の PHP を有効にする
と をインストール. PHP パッケージには、 USE フラグの設定が必要:

ファイルを編集:

必要なディレクトリの作成:

PHP ラッパーへのシンボリックリンクを張る:

Enable the  module:

最後に、Apache を再起動して、すでに作成された サイトを確認します. の値は CGI/FastCGI になるはずです.

Apache 2.4でmod_proxy_fcgiを使ってPHP-FPMを使う
PHP の 5.3 以上では、FastCGI およびプロセスマネージャー、FPM のサポートが追加されています.

The following method 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, 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:

Then enable both the  and   modules:

OpenRC
Apache サーバを起動:

Add Apache to the default runlevel:

Apache サービスを再起動:

Reload Apache configuration files:

systemd
Start the Apache server:

Apache を default ランレベルに追加:

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 - 高速軽量ウェブサーバ
 * Nginx - 小型で強靭、高性能なHTTPサーバ兼リバースプロキシ

外部の情報

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