Share your love
How To Upgrade PHP Version on Ubuntu 20.04

In this guide, we want to teach you How To Upgrade PHP Version on Ubuntu 20.04. PHP is an open-source, interpreted, and object-oriented scripting language that can be executed on the server side. PHP is well-suited for web development. Therefore, it is used to develop web applications (an application that executes on the server and generates the dynamic page).
You can now proceed to the guide steps below on the Orcacore website to upgrade the PHP Version on Ubuntu 20.04.
Table of Contents
Steps To Upgrade PHP Version on Ubuntu 20.04
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on the Initial Server Setup with Ubuntu 20.04.
1. Check Current PHP Version on Ubuntu 20.04
The default PHP version on Ubuntu 20.04 is 7.4. To verify your current PHP version, run the command below:
php -v
At this point, in your output, you should see:

2. Remove PHP 7.4 From Ubuntu 20.04
To upgrade your PHP version, you must remove the current PHP version. To do this, run the command below:
sudo apt purge php7.*
After uninstalling packages, run the commands below:
# sudo apt autoclean
# sudo apt autoremove
3. Add Ondřej Surý’s PPA repository on Ubuntu 20.04
If you are running Ubuntu 20.04 or 18.04, the PHP 8 binary packages are only available in the Ondřej Surý PPA repository. To add the repository, run the command below:
sudo add-apt-repository ppa:ondrej/php
When your installation is completed, you can proceed to the next step.
4. Update PHP Version on Ubuntu 20.04
First, update your local package index with the command below:
sudo apt update
Then, use the command below to install the latest version of PHP:
sudo apt install php8.1 -y
At this point, you can check your PHP version:
php -v

The command below includes some of the most popular PHP extensions:
sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl -y
Conclusion
In conclusion, upgrading the PHP version on Ubuntu 20.04 involves adding a trusted third-party repository like Ondřej Surý’s PPA, installing the desired PHP version, and updating configuration files if needed. This process ensures compatibility with newer applications and improves performance and security on your system.
Hope you enjoy it. Please subscribe to us on Facebook, YouTube, and X.
Also, you may like these articles:
How to install MariaDB on Ubuntu 20.04