How to Install and Use Multiple Versions of PHP on Debian/Ubuntu

Performance of PHP is greatly increased in the version 7.0 and support for the older version will be ended in newer future. So it is now critical to update your PHP version. But at the same point, there are applications of environment that demand older version of PHP. You may need to run several versions of PHP under one apache server.

I looked at the various options and I was given the launch of the old version of PHP 5.6 via FastCGI. So, I already have the Apache server installed and PHP 7.0 installed. Let’s start with downloading and building PHP 5.6.

We need to execute the folowing necessary commands to prepare your machine to build and execute the application from source code.

apt-get -y install build-essential libfcgi-dev libfcgi0ldbl libjpeg62-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-lib libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev pkg-config

Now you need to prepare directory to compile and run the project.

Next, configure and compile php-5.6.34.

./configure –prefix=/opt/php-5.6.30 –with-config-file-path=/opt/php-5.6.340 –with-pdo-pgsql –with-zlib-dir –with-freetype-dir –enable-mbstring –with-libxml-dir=/usr –enable-soap –enable-calendar –with-curl=/usr/bin –with-mcrypt –with-zlib –with-gd –with-pgsql –disable-rpath –enable-inline-optimization –with-zlib –enable-sockets –enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex –with-mhash –enable-zip –with-pcre-regex –with-mysql –with-pdo-mysql –with-mysqli –with-jpeg-dir=/usr –with-png-dir=/usr –enable-gd-native-ttf –with-openssl –enable-ftp –with-kerberos –with-gettext –enable-cli –enable-fastcgi –enable-discard-path –enable-force-cgi-redirect –enable-cgi

compile and install

At the end of the run, you will have the compiled version of php-5.6.34 in the /opt/php-5.6.34/ directory.

Next, you need to install the module for apache.

and run it and another module.

Next, edit the configuration file /etc/apache2/mods-enabled/fastcgi.conf (cite the contents).

Then we create a wrapper through which the php scripts will be executed.

Let’s add the execution rights.

Create an apache configuration file with the settings of the php script handler.

It remains to create a configuration file for the virtual host and add the import php56.conf.

Add this virtual host to the Apache configuration

and restart the service

To verify, create a file

Another site with the higher version of php,

Voila. You have now multiple versions of PHP on the same server.

Authored By Imran Yousaf

I am Imran Yousaf, a computer geek, founder of the site I am a die hard fond of open-source software and Linux operating system. In addition to Linux, I am interested in everything related to information technology and modern science.

Leave a Reply

Your email address will not be published. Required fields are marked *