Nginx – Run a specivic (older) php version with nginx, php-fpm on debian

debiannginxPHPphp-fpm

In order to migrate old php software, I want to run php 5.3.* so I:

  1. Removed php via apt-get purge php*
  2. Added the corresponding http://snapshot.debian.org/archive/debian/ to the sources
  3. Installed apt-get install php5=5.3.10-2

Now if I do apt-cache policy php5 I get:

php5:
  Installed: 5.3.10-2
  Candidate: 5.6.17+dfsg-0+deb8u1
  Version table:
     5.6.17+dfsg-0+deb8u1 0
        500 http://ftp.debian.org/debian/ jessie/main amd64 Packages
     5.6.14+dfsg-0+deb8u1 0
        500 http://security.debian.org/ jessie/updates/main amd64 Packages
 *** 5.3.10-2 0
        500 http://snapshot.debian.org/archive/debian/20120221T041601Z/ unstable/main amd64 Packages
        100 /var/lib/dpkg/status

So far so good, my nginx setup is like:

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

But now if I do php -v I get:

PHP 5.6.17-0+deb8u1 (cli) (built: Jan 13 2016 09:10:12)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

And also if I serve <?php phpinfo(); ?> I get:

PHP Version     5.6.17-0+deb8u1

dpkg -l php5* | egrep ^ii outputs:

ii  php5            5.3.10-2             all          server-side, HTML-embedded scripting language (metapackage)
ii  php5-cli        5.6.17+dfsg-0+deb8u1 amd64        command-line interpreter for the php5 scripting language
ii  php5-common     5.6.17+dfsg-0+deb8u1 amd64        Common files for packages built from the php5 source
ii  php5-fpm        5.6.17+dfsg-0+deb8u1 amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php5-json       1.3.6-1              amd64        JSON module for php5
ii  php5-readline   5.6.17+dfsg-0+deb8u1 amd64        Readline module for php5

So what are the necessary steps to actually run the older version of php?

Edit: I found this https://github.com/phpbrew/phpbrew really helpful tool. So if someone facing the same issue this might be a good solution.

Best Answer

You will also need to run:

apt-get install php5-cli=5.3.10-2 php5-fpm=5.3.10-2 php5-common=5.3.10-2 php5-readline=5.3.10-2

These were still on the 5.6 version, that's why you still see 5.6.