Skip to main content

Working with multiple versions of PHP 7.3, 7.2, 7.1, 7.0 & 5.6 on Ubuntu

 

Sometimes PHP developers need to work on multiple versions of PHP for different projects and one might think of using a docker installation, which is a better idea of what we are going to do below, but Docker can be complicated for many reasons and one might not be ready to get started with Docker. In the below article, I will be explaining how one can work with multiple PHP version on Ubuntu. I am using ubuntu 18.10 and the below article for me without any issues.

Install PHP (5.6, 7.0, 7.1, 7.2 and 7.3) on Ubuntu Using PPA

1.  Adding OndÅ™ej PPA to install different versions of PHP – PHP 5.6PHP 7.0, PHP 7.1, PHP 7.2 and PHP 7.3 on the system.

sudo apt-get install software-properties-common

## sudo apt install python-software-properties

sudo add-apt-repository ppa:ondrej/php

2.  Update the system

Make sure you have the sudo privileges to do so.

sudo apt-get update



3. Add different versions of PHP as required

I will be adding fpm version as well, you may ignore them if you do not need them

sudo apt install php5.6 php5.6-fpm

sudo apt install php7.0 php7.0-fpm

sudo apt install php7.1 php7.1-fpm

sudo apt install php7.2 php7.2-fpm

sudo apt install php7.3 php7.3-fpm

4. You might need to add the most common modules one normally uses with PHP

I work a lot with Laravel, WordPress, Symfony, EspoCRM & Zend Framework so I shall add the below modules for all the PHP versions

For PHP 5.6

sudo apt install php-gmagick php5.6-xml php-ssh2 php5.6-curl php5.6-gd php5.6-mbstring php5.6-mysql php-tokenizer php-xdebug php-apcu php5.6-bcmath php5.6-bz2 php-memcache php-zip

For PHP 7.0

sudo apt install php-gmagick php7.0-xml php-ssh2 php7.0-curl php7.0-gd php7.0-mbstring php7.0-mysql php-xdebug php-apcu php7.0-bcmath php7.0-bz2 php-memcache php7.0-zip

For PHP 7.1

sudo apt install php-gmagick php7.1-xml php-ssh2 php7.1-curl php7.1-gd php7.1-mbstring php7.1-mysql php-xdebug php-apcu php7.1-bcmath php7.1-bz2 php-memcache php7.1-zip

For PHP 7.2

sudo apt install php-gmagick php7.2-xml php-ssh2 php7.2-curl php7.2-gd php7.2-mbstring php7.2-mysql php-xdebug php-apcu php7.2-bcmath php7.2-bz2 php-memcache php7.2-zip

For PHP 7.3

sudo apt install php-gmagick php7.3-xml php-ssh2 php7.3-curl php7.3-gd php7.3-mbstring php7.3-mysql php-xdebug php-apcu php7.3-bcmath php7.3-bz2 php-memcache php7.3-zip

Well the above should be more than enough to get you started with your PHP projects.

5. Check the installed versions of PHP

Execute the following command to check all the versions of PHP installed on the system:

ls -al /usr/bin | grep php

-------------------------- output -------------------------------

lrwxrwxrwx 1 root root 21 Mar 26 2020 php - /etc/alternatives/php*

-rwxr-xr-x 1 root root 4512600 Jan 16 12:12 php5.6*

-rwxr-xr-x 1 root root 4508520 Dec 10 11:23php7.0*

-rwxr-xr-x 1 root root 4665176 Jan 20 20:56 php7.1*

-rwxr-xr-x 1 root root 5014552 Feb 14 22:26 php7.2*

-rwxr-xr-x 1 root root 4769528 Feb 18 01:33 php7.3*

To check your current version of PHP execute the following command:

php -v


It should output something as below:

PHP 7.3.2-3+ubuntu18.10.1+deb.sury.org+1 (cli) (built: Feb 18 2019 15:44:30) ( NTS ).

Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies

with Zend OPcache v7.3.2-3+ubuntu18.10.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

with Xdebug v2.7.0RC2, Copyright (c) 2002-2019, by Derick Rethans

Compiling extensions or working with PHP Dev tools?

If you are planning to compile shared PECL extensions install the PHP dev tools for respective version

sudo apt install php5.6-dev

sudo apt install php7.0-dev

sudo apt install php7.1-dev

sudo apt install php7.2-dev

sudo apt install php7.3-dev

6. Changing PHP version

One may use the command `update-alternatives` to update the default PHP version

For changing PHP version to 5.6 execute the following command

sudo update-alternatives --set phpize /usr/bin/phpize5.6

sudo update-alternatives --set php /usr/bin/php5.6

sudo update-alternatives --set php-config /usr/bin/php-config5.6

For changing to PHP 7.0:

sudo update-alternatives --set phpize /usr/bin/phpize7.0

sudo update-alternatives --set php /usr/bin/php7.0

sudo update-alternatives --set php-config /usr/bin/php-config7.0

For changing to PHP 7.1:

sudo update-alternatives --set phpize /usr/bin/phpize7.1

sudo update-alternatives --set php /usr/bin/php7.1

sudo update-alternatives --set php-config /usr/bin/php-config7.1

For changing to PHP 7.2:

sudo update-alternatives --set phpize /usr/bin/phpize7.1

sudo update-alternatives --set php /usr/bin/php7.1

sudo update-alternatives --set php-config /usr/bin/php-config7.1

For changing to PHP 7.3:

sudo update-alternatives --set phpize /usr/bin/phpize7.3

sudo update-alternatives --set php /usr/bin/php7.3

sudo update-alternatives --set php-config /usr/bin/php-config7.3


For PHP professionals working on multiple frameworks, using multiple versions of PHP becomes inevitable. Hope the above content help others as it is was helpful for me.

Comments

Popular posts from this blog

How to Speedup your WordPress site with Amazon CloudFront.

Introduction A WordPress performance is quite excellent . The number of WordPress plugins to handle performance is such evidence. But the easiest way to improve your user experience is to accelerate the entire WordPress website using CloudFront. This will help you not only improve site response time reduces the necessary infrastructure, reducing the load on the Web server, so you can reduce the total cost of the infrastructure works WordPress. CloudFront is actually a site can greatly help your site to respond to unexpected load when gained popularity. Today this post is to clarify the method of providing a reasonable standard configuration on the WordPress website or blog. How does CloudFront help? Amazon CloudFront is to improve the user's experience accessing the Web site in several ways: 1.  Anycast DNS is to ensure that customers are routed to the nearest edge location. 2.  The cached content is available to users at the edge position (i

Linux System : Free Employee Monitoring with Automatic Screenshots

Introduction :   A utomatic screen-shots  of Linux system directly import  on your web server with Linux samba server service and scrot command. 1)  Setup web panel UI on your web server :   Get web panel PHP/HTML code from Github URL: https://github.com/raj412/Employee-Monitoring-for-Linux-System It’s work in Linux server LAMP environment(no need database for this configuration ) Defult login username password is admin/1234. You can change username/passwrod from login.php file in line number #6 Login Page : Dashboard : Screenshot Page : 2)  Samba server configuration on web server : I.  Install Samba on your server where you setup Linux screenshot log system web panel. sudo apt-get update sudo apt-get install samba II.  Set a password for your user in Samba sudo smbpasswd -a <user_name> III.  Share gallery-images folder from you web panel. This is my web panel gallery-images p

How to control high traffic load on Apache servers : optimization performance of APACHE2 & PHP-FPM

Everyone handle high traffic loads  on Apache server. During down-time they forget to check server memory . Apache not used lot of memory  still server not responding. All time we restart Apache service and all things will start working good. I also faced same issue numerous time and all-time  used same solution : Restart Apache. After lots of research and reading found one solution. In this blog you see step-by-step guide to apache2 performance settings. System environment: Intel(R) Xeon(R) CPU 3.10GHz, 4 cores | 8GB RAM Ubuntu 16.04 Apache2 version using mpm_event PHP FPM (5.6,7.1) First,  Calculate process size : Download : python script file “ps_mem.py” from Github Open this and ps_mem.py file upload on you server :  https://github.com/raj412/ps_mem chmod a+x ps_mem.py sudo python ps_mem.py Output like this:  See here : 12 Apache processes, consuming a total of  35.7MiB, so each Apache process is using roughly 3MiB of RAM. The 42 php-fpm process u