Upgrade PHP Version to PHP7.4 on Ubuntu

Upgrade php version on ubuntu

Step by step guide to upgrade PHP version to PHP7.4 on ubuntu. You can upgrade your PHP version to latest release PHP7.4 on your ubuntu18.04 or Ubuntu 20.4.

This upgrade is tested on EC2 instance running Ubuntu 18.04 or Ubuntu 20.4 OS on AWS (Amazon Web Server). So the steps mentioned in this guide works on any cloud servers like AWS, DigitalOcean, Linode, Vultr or any VPS or Dedicated servers running Ubuntu 18.04 or Ubuntu 20.4.

Add PPA for PHP 7.4

Add the ondrej/php which has PHP 7.4 package and other required PHP extensions.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Once you have added the PPA you can install PHP 7.4.

Install PHP 7.4 for Apache

Execute the following command to install PHP 7.4

sudo apt install PHP7.4

Install PHP 7.4 Extensions

Now, install some commonly used php-extensions with the following command.

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

After this check php version using following command.

php -v

Enable PHP 7.4 for Apache

Now you need to tell apache to disable old module of PHP module (below I have mentioned step for PHP7.2, You need to replace it with your current PHP version) and enable the new php module using following command.

sudo a2dismod php7.2
sudo a2enmod php7.4

Restart Apache for the changes to take effect.

sudo service apache2 restart

Conclusion – It’s very easy and tested guide to upgrade your older PHP version to the PHP7.4. This guide may save your life in case your code require latest PHP version.

Try this and if you face any issue please mention in the comment. I will surely help you in this.

× How can I help you?