back_image
blog-image

How to Update PHP 7.2 to PHP 7.4 and Use Multiple PHP Rendition on Ubuntu 20.04

Author Image By Ashish Dwivedi

Last Updated: September 24, 2024

2 minutes

This tutorial will guide you on how to upgrade PHP 7.2 or any other older version to PHP 7.4.

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.4. 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 its Extensions.

apt-get install php7.4
apt-get install libapache2-mod-php7.4
sudo apt-get install php7.4 php7.4-cli php7.4-common
sudo apt-get install php7.4-json php7.4-opcache
sudo apt-get install php7.4-mysql
sudo apt-get install php7.4-bcmath php7.4-xml
sudo apt-get install php7.4-curl php7.4-imap php7.4-gd

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

cd /etc/php/7.4/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.4

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.4.5-1+ubuntu20.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+ubuntu20.04.1+deb.sury.org+1, Copyright (c) 1999- 2018,  by Zend Technologies

As you already have seen, you have PHP 7.4, go to the webroot of the server i.e. /var/www/html, and Create a file info.php.

Put this content into this file

Now reach 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.4 in our case.

Now if you want to use different PHP for different websites, Go to 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.4 then Click this URL: https://www.php.net/eol.php