PHP/ja

PHPは、動的なWebページを生成する汎用のサーバー側スクリプト言語です.

USE フラグ
The most important USE flags of the PHP package, the SAPI (Server API) USE flags, are, , and. Alongside these flags, there is an elaborate list of flags to enable various features of the PHP interpreter:

デフォルトでは、ebuildは開発用のバージョンをインストールします. より厳密なセキュリティ設定がありますが、アプリケーションをデバッグするのが難しい製品バージョンをインストールするには、に次の行を追加します:

拡張
To install extensions, first decide which versions of PHP to compile the extensions for. This is done by setting the PHP_TARGETS variable:

More than one version can be defined; just add in the additional versions separated by a space. Note that the php slot is named "5.6" and the corresponding PHP_TARGETS value is. This is due to current restrictions on USE names.

Emerge
上記のUSEフラグ設定を行った後、変更を有効にするためにシステムを更新する必要があります:

Running multiple versions of PHP
One of the great advantages of using Gentoo for PHP development is the version slotting. It is very simple to swap between multiple versions of PHP as well as run multiple versions simultaneously. This is all done with the command provided by the  package which should get emerged in automatically by installing PHP.

For example, selecting different versions of PHP can allow a system to run PHP 7.0 for the cli SAPI but PHP 5.6 for the system's web server. It also allows system administrators or application developers to quickly test an application on different versions of PHP.

To list the available versions for the cli SAPI module use the following syntax:

The  (asterisk) marks current active version for the selected module. To check the other SAPIs simply replace  with ,  or   modules.

To swap versions, use:

The number  in this example corresponds to the number in the output of the   sub-command used above. PHP version 7.0 is now used for the command-line:

設定
The PHP configuration is at, which contains one subdirectory for each Server API (SAPI) and for each PHP version. For instance, configuration files for the PHP-5.6 apache2 SAPI are installed in.

ウェブサーバ
PHPをサーバ側で使用するには、WebサーバをインストールしてPHPを使用するように設定する必要があります. 数多くの一般的なWebサーバーが次に簡単に触れられます.

Nginx
Simply emerge nginx to install it:

Once Nginx has been installed, modify the server section of to look something like this:

Now start the related services to have a working site. The init script starts the PHP FastCGI Process Manager. FastCGI allows web servers to offload the PHP calculations to this process manager.

When running OpenRC as the service manager:

For systemd:

lighttpd
Make sure that lighttpd is built with support for  and that the   USE flag is disabled:

Lighttpd ships with a default FastCGI config file, but unfortunately, it is written to work with the old PHP FCGI SAPI only, instead of a general FCGI setup. Since the  USE flag has been disabled, it will not be included, and rightly so. However it does provide a good foundation for a configuration file that can be used with FPM.

Edit to look something like this:

Note the  and   parts.

Since Gentoo ships with a working file, located in, and init script, starting the services is all that is needed:

Apache (mod_php)
To configure Apache to load the PHP5 module (mod_php), add  to APACHE2_OPTS variable in. Users might remember that previously, the PHP version had to be added as well (like ). However, since version 0.8.1, the variable is changed to just   to allow future major versions to be easily integrated.

Make sure that PHP is built with the  USE flag.

If for some reason the system is missing the PHP module integration file, currently provided by when installed with   USE flag set, manually insert it. Its current content is displayed below.

Although multiple PHP versions can be installed on a system, Apache can only use a single PHP version with mod_php. Support for multiple PHP versions on Apache is available using fpm. The command is used to switch between active mod PHP versions.

参考

 * Upgrading to PHP 5.6, guide to upgrade older installations to 5.6
 * Upgrading to PHP 7.1, guide to upgrade older installations to 7.1
 * Enabling PHP support in the Apache article