PHP

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

Installation
The installation guide of PHP on Gentoo written by the PHP herd covers how to install PHP on your Gentoo system.

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.

Now, lets say you want to run two php-fpm servers, with two different versions, for two different websites. There is a nifty feature in the php-fpm init script which will do this for you. Symlink the global php-fpm script to all the versions you would like to run simultaneously. So if I wanted to run both PHP 5.3 and PHP 5.4 I would do this.

Now, I will need to stop any running instances on the global PHP as we don't want the global and slotted version fighting for the same port.

Also, because php-fpm binds itself to a port we need our two versions to use two separate ports so let's update the 5.4 config.

I can now use my new slotted init scripts to launch the different versions.

From here you just need to adjust the port setting in your web server configuration (Apache2, nginx, lighttpd, etc.) to use the port of the version you are interested in for each of your server's virtual hosts.