PHP
PHP is a general-purpose server-side scripting language to produce dynamic Web pages.
Contents |
Installation
dev-lang/php
Portage knows the global USE flag php for enabling support for PHP in other packages. Enabling this USE flag will pull in dev-lang/php automatically:
USE="... php ..."
The most important USE flags of php, the SAPI (Server API) USE flags, are:
| USE flag | Default | Recommended | Description |
|---|---|---|---|
| apache2 | No | Add Apache2 support | |
| cgi | No | Add CGI script support | |
| cli | Yes | Enable CLI SAPI | |
| embed | No | Enable embed SAPI | |
| fpm | No | Enable the FastCGI Process Manager SAPI |
Also check the other USE flags.
By default the ebuild installs the development php.ini version. If you want to install the production version add the following to your make.conf:
PHP_INI_VERSION="production"
Both versions of php.ini can be found in /usr/share/doc/php-*.
After setting this you want to update your system so the changes take effect:
root # emerge --ask --changed-use --deep @worldExtensions
If you want to install extensions, you can decide which versions of PHP you want extensions compiled for. This is done by setting the PHP_TARGETS variable:
PHP_TARGETS="php5-4"
You can also set more than one. Note that the php slot is named "5.4" and the corresponding PHP_TARGETS setting is php5-4. This is due to current restrictions on USE names.
After setting this you want to update your system so the changes take effect:
root # emerge --ask --changed-use --deep @worldRunning 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 eselect command provided by the app-admin/eselect-php package which should get pulled in automatically with your installation. This allows you to run, for example, PHP 5.3 for your cli SAPI but PHP 5.4 on your web server. It also allows you to quickly test your application on different versions of PHP.
To list the available versions for the cli SAPI use:
root # eselect php list cli
[1] php5.3
[2] php5.4 *
[3] php5.5
The version marked with the * is the current active version, and to check the other SAPIs simply replace cli with fpm,cgi,apache2.
To swap versions use:
root # eselect php set cli 1where 1 corresponds to the number in the output of "show".
You are now running PHP 5.3 on command line.
root # php -v
PHP 5.3.9-pl0-gentoo (cli) (built: Jan 30 2012 13:21:46)
Configuration
The PHP configuration is in /etc/php, which contains one subdirectory for each SAPI for each PHP version, e.g. configuration files for the PHP-5.4 apache2 SAPI are installed in /etc/php/apache2-php5.4.
To setup Apache to use PHP, see the Apache article.