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.).
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 the Initial Server Setup with Ubuntu 20.04.
Check Current PHP Version
The default PHP version on Ubuntu 20.04 is 7.4. To verify your current PHP version run the command below:
At this point, in your output you should see:
Output PHP 7.4.3 (cli) (built: Aug 17 2022 13:29:56) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
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
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.
Upgrade PHP Version
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
At this point, you can check your PHP version:
Output PHP 8.1.11 (cli) (built: Sep 29 2022 22:28:49) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.11, Copyright (c) Zend Technologies with Zend OPcache v8.1.11, Copyright (c), by Zend Technologies
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
At this point, you have learned to Upgrade the PHP version on Ubuntu 20.04.
Hope you enjoy it.
Also, you may be like these articles:
How to install MariaDB on Ubuntu 20.04
set up Apache virtual host on Ubuntu 20.04