PHP

PHP is a general-purpose server-side scripting language to produce dynamic Web pages.

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 automatically:

The most important USE flags of php, the SAPI (Server API) USE flags, are:

Also check the other USE flags.

By default the ebuild installs the development version. If you want to install the production version add the following to your :

Both versions of can be found in.

After chaning the preferred version of php.ini, you need to reinstall PHP:

Extensions
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:

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:

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 eselect command provided by the 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:

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:

where 1 corresponds to the number in the output of "show".

You are now running PHP 5.3 on command line.

Configuration
The PHP configuration is in, 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.

To setup Apache to use PHP, see the Apache article.

Replacing PHP 5.4 with PHP 5.5
Set the PHP_TARGETS variable.

Uninstall incompatible extensions
Remove all old extensions that do not build for PHP 5.5. I recommend using eix for this task. Note that when piping to emerge, you cannot use interactive mode so --ask on the emerge command is not applicable here.

Be sure to migrate USE flags if you have specified versions in your package.use file(s).

Remove APC
Remove APC as you cannot have APC installed with PHP 5.5 with the opcache USE flag (which is by default turned on).

Installation
Install PHP 5.5:

Replacing APC
If you are building with the opcache USE flag (the default) but need APC user-land functions such as apc_fetch, install APCu, which emulates APC but only has user caching functions. This may be necessary for older projects that rely on APC for caching.

If necessary, unmask it:

Install APCu:

Stop PHP-FPM
Stop PHP-FPM if you are using it.

Switch to PHP 5.5
Switch to it using eselect for all SAPIs:

If you have other SAPIs, be sure to run eselect for those as well.

Non-eix method
Since changing PHP_TARGETS is technically a USE flag change, you should be able to simply emerge @world with flags checking for new USE flags and all extensions should re-build.

eix method
Re-install all your installed extensions that can build for PHP 5.5:

Clean up
Since you removed extensions, it may be useful to run a dependency clean up at this point for older ones that are no longer compatible.