Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc


PHP5 and PHP6 Simultaneously

This article is still a Stub. You can help Gentoo-Wiki by expanding it.


Warning: This method has not been well-tested, use at your own risk!

PHP6 will be the next biggest change in PHP applications world, it would be great to have an early testing environment for PHP6 - it might save some nightmares to developers.




This method can be summarized in a few steps:

  1. Install Apache and PHP5 as usual (using emerge)
  2. Manually install PHP6 (as there is no ebuild for it, yet)
  3. Configure Apache for the specific directory dedicated to PHP6

Install Apache and PHP5

If you already have apache & php5 installed, you can skip this step.

Just install apache and php5 the usual way using portage: (note: "server ~ #" is the bash prompt, also replace version numbers with whatever applies)

Code: Installing apache and php5
 server ~ # emerge apache php -av
 These are the packages that I would merge, in order:
 Calculating dependencies ...done!
 [ebuild   R   ] net-www/apache-2.2.4
 [ebuild   R   ] dev-php/php-5.2.4

 Do you want me to merge these packages? [Yes/No] y

Manually install PHP6

This is the tricky part, read calmly and with attention.

Emerging needed packages

PHP6 will need some packages that you might not have installed:

Code: Additional packages
 server ~ # emerge libtool bison flex re2c icu

Read more about ICU

NOTE: you will also need autoconf, automake and libtool, but they should be already installed if you have previously installed PHP5.

Possible autoconf issues

If buildconf execution went OK, proceed to the next section.

If you have troubles with autoconf 2.61 (which is used by PHP5, for example), you might have better luck with autoconf 2.13, which is the suggested one (by PHP6's buildconf itself) for PHP6 compilation.

In such case, proceed as follows:

Code: Using autoconf 2.13
 server ~ # emerge --unmerge autoconf
 server ~ # emerge '=sys-devel/autoconf-2.1*'

You might want to put back autoconf 2.61 when you're finished compiling PHP6.

Download & prepare

First, we will have to get the .tar.bz2 archive containing the nightly build.

Go visit and then copy the link of the latest PHP6 package (the one in .tar.bz2 format); next, proceed as follows:

Code: Download & prepare
 server ~ # wget
 server ~ # tar xvjf php6.0-200709082230.tar.bz2
 server ~ # cd php6.0-200709082230
 server php6.0-200709082230 # ./buildconf
 server php6.0-200709082230 # ./configure --with-icu-dir=/usr/local/icu --with-mysql=/usr/bin

NOTE: you can add more flags to ./configure command line, run ./configure --help to get help about them. The --with-mysql part is not necessary if you do not have MySQL, while the --with-icu-dir is highly suggested.
NOTE: if you get an error try to change ICU dir to /usr [corrected by holms]

PHP6 installation

Now we will proceed to the actual installation of PHP6 in your system; I have not been able to install it in /usr/local/php6 so the installation will install it side-by-side with PHP5, but since PHP6 is installed as CGI it should not conflict with PHP5 (it has not yet on my system).

Code: PHP6 installation
 server php6.0-200709082230 # make
 server php6.0-200709082230 # make install

Manually updating PHP6

As PHP6 is still in development, you might want to update it regularly. You can either regularly checkout the sources using CVS or proceed as explained above each time you want to re-install PHP6; the new installation will overwrite the previous one.

NOTE: you will not need to reconfigure Apache when updating PHP6

Test PHP5 and PHP6

At this point you should be done! As a test, run the following informative commands:

Code: PHP5 and PHP6 test
 server php6.0-200709082230 # php-cgi --version
PHP 6.0.0-dev (cgi-fcgi) (built: Sep  8 2007 23:09:52)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2007 Zend Technologies
 server php6.0-200709082230 # /usr/bin/php --version
PHP 5.2.4-pl2-gentoo (cli) (built: Sep  8 2007 17:44:47) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

NOTE: apache will still use /usr/bin/php for .php files outside /php6

Configure Apache

In this section we will configure Apache to handle .php files in a subdirectory of the DocumentRoot, /php6 for example, be executed through php-cgi.

Create the file /etc/apache2/modules.d/php6-cgi.conf with the following content

Code: php6-cgi.conf
# handler for PHP 6 scripts
<IfDefine PHP6CGI>
    ScriptAlias /php6-cgi /usr/local/bin/php-cgi
    Action php6-cgi /php6-cgi
    AddHandler php6-cgi .php6

Edit your /etc/conf.d/apache2 file placing the -D PHP6CGI in the APACHE2_OPTS variable.

Edit your /etc/apache2/httpd.conf file performing the following modifications:

Code: Modifications to http.conf
<IfDefine PHP6CGI>
## This block will allow execution of php-cgi
<Directory /usr/local/bin>
        <files php-cgi>
                allow from all
                options execcgi

NOTE: following instructions apply if you are using the default VirtualHost (default Apache2 configuration), otherwise find your VirtualHost declaration and modify it

Go edit /etc/apache2/vhosts.d/00_default_vhost.conf and perform these modifications:

Code: Modifications to VirtualHost
<VirtualHost *:80>
<IfDefine PHP6CGI>
# Add handler for PHP6-enabled scripts
        <IfDefine PHP6CGI>
            ScriptAlias /php6-cgi /usr/local/bin/php-cgi
            Action php6-cgi /php6-cgi
            AddHandler php6-cgi .php6

        <Location /php6>
                AddHandler php6-cgi .php

Testing PHP6

We are now ready to test what we have done. Let's create the PHP6-dedicated /var/www/localhost/htdocs/php6/ directory and place a test file there:

Code: Testing PHP6
 server ~ # mkdir /var/www/localhost/htdocs/php6/
 server ~ # echo "<?php phpinfo(); ?>" > /var/www/localhost/htdocs/php6/phpinfo.php

Now open up your browser and access the following URL:


Previewing with a symbolic link

You might add a symbolic link into /php6 to test simultaneously files with php5 and php6.

Code: Create symlink to DocumentRoot
 server ~ # ln -s /var/www/localhost /var/www/localhost/htdocs/php6/www

Once the done the above, you will have:

End notes

Please help better defining this tutorial either modifying it or posting to the Talk:HOWTO_PHP5_and_PHP6_Simultaneously page; if you have reached the goals through a different path, also post there your instructions and somebody else might update this howto if you didn't already.

Many thanks to D.Coallier for the PHP6 installation tutorial and to rici for having helped during the first attempt of Apache2 setup.

See also

Retrieved from ""

Last modified: Sun, 03 Aug 2008 10:03:00 +0000 Hits: 5,713