back_image
blog-image

How to Upgrade PHP to php7.2 and use Multiple PHP Rendition on Ubuntu 18.04

Author Image By Ashish Dwivedi

Last Updated: January 31, 2022

57 minutes

This tutorial will guide you to upgrade PHP to 7.2 from any past versions like 5.6 or 7.0.

So you know you already understand the time for 5.6 and 7.0 passed out months ago.

So let us plan to upgrade PHP to the latest ie 7.2. Which comes with several safety stains. As a mighty upgrade strategy, Always Backup 100% first. So keep everything backup accompanied by databases.

At Ubuntu, with my particular experience, before starting any advance, always start with 2 commands.

1) Become Sudo user with the command “sudo su” and then

    apt-get update    

    apt-get upgrade

2) Now time to include “Ondrej PPA”

    sudo apt-get install software-properties-common

    sudo add-apt-repository ppa:ondrej/php

    apt-get update

3) Now install PHP and it’s Extensions.

    apt-get install php7.2

    apt-get install libapache2-mod-php7.2

    sudo apt-get install php7.2 php7.2-cli php7.2-common

    sudo apt-get install php7.2-json php7.2-opcache

    sudo apt-get install php7.2-mysql

    sudo apt-get install php7.2-bcmath php7.2-xml

    sudo apt-get install php7.2-curl php7.2-imap php7.2-gd

 4) Now time to modify php.ini to add server execution

     cd /etc/php/7.2/apache2

     nano php.ini

    memory_limit ( 40 - 50 % of Memory),

    max_file_uploads (20 - 50),

    post_max_size (40 - 50 % of Memory),

    max_execution_time (3600) ,

   upload_max_filesize ( 40 - 50 % of Memory),

    max_input_time = 1000

5) Now disable old PHP and enable a new PHP version

    a2dismod php5.6  or a2dismod php7.0

    a2enmod php7.2

6) Time to restart Apache

    Service apache2 restart

7) Now type php -v or php –version

  You should get a message like this

PHP 7.2.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May  3 2019 10:00:24) ( NTS )

Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.5-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999- 2018,  by Zend Technologies

As you already have seen, you have PHP 7.2, go to the webroot of server ie /var/www/html, Create a file info.php.

      Put this content  into this file

Now reach to this file via browser-ie https://mydomain/info.php

So your command line PHP (PHP-CLI) and PHP on the browser must be the same version. ie php7.2 in our case.

Now if you want to use different PHP for different websites, Go this article.

“To be summarised, Keeping sustained upgrades of software and servers, pushing you ahead in the set-to, as new upgrades come with protection upgrades and patches. Also, It has seen considerable speed improvements after upgrades.”

Anyone Update PHP 7.3 then Click this url : https://www.php.net/eol.php

Stay updated by signing up for our newsletter

Read our full Privacy Policy here.