PHP is a coding language used to develop websites, and web applications as most of the applications run on the server. PHP 8.0 is the most recent version of PHP and it is more stable than all previous versions. It stabilizes the aspects such as match expression, improved type system, consistency, error handling, named arguments, union types, and many more.
This writeup elaborates the instructions for PHP 8 installation on Ubuntu 22.04.
PHP 8 Installation on Ubuntu 22.04
To install PHP 8 on Ubuntu 22.04, follow the below-given guide.
Step 1: Update APT Cache Repository
First, open Ubuntu 22.04 terminal by utilizing “CTRL+ALT+T” and update the package repository:
$ sudo apt update
Let’s move forward toward the next step.
Step 2: Installation of Required Prerequisites
In the next step, install all necessary prerequisites:
$ sudo apt install apt-transport-https lsb-release software-properties-common ca-certificates -y
Once installed, move ahead toward the next step.
Step 3: Add PHP PPA Repository
To add the PPA repository of PHP, use the below command:
$ sudo add-apt-repository ppa:ondrej/php
After adding the repository, move ahead to the installation of PHP latest version.
Step 4: Install PHP 8.0
After adding the repository, use the mentioned command to install PHP 8.0:
$ sudo apt install php8.0 -y
Go to the next step to confirm the PHP 8 installation.
Step 5: Verify Installation of PHP 8
Confirm PHP 8.0 installation by verifying its version:
$ php -v
We have installed the PHP “8.0.20” version on Ubuntu 22.04:
Step 6: PHP 8 Extensions Installation
Install PHP 8 extensions using given command:
$ sudo apt install php8.0-cli php8.0-common php8.0-imap php8.0-redis php8.0-xml php8.0-zip php8.0-mbstring
Step 7: Enable PHP 8
By default, PHP 8 is disabled on Ubuntu 22.04. To enable PHP services on Ubuntu 22.04, run the following command:
$ a2enconf php8.0-fpm
Step 8: Check PHP 8 Service Status
Lastly, check the status of PHP 8 services:
$ systemctl status php8.0-fpm
We have successfully installed PHP 8.0 on Ubuntu 22.04. Let’s move ahead to check out the uninstallation method.
PHP 8 Uninstallation on Ubuntu 22.04
To uninstall PHP 8.0 from Ubuntu 22.04, use the provided command:
$ sudo apt-get purge php8.*
Next, execute the below-given command to remove the directory of PHP 8 from Ubuntu 22.04:
$ sudo rm -rf /etc/php/8.0/*
We have illustrated the way to install and remove PHP 8 on Ubuntu 22.04.
On Ubuntu 22.04, for PHP 8 installation, first, update the packages of the system and install the necessary packages. After that, add the PHP PPA repository to the system. Then, install PHP 8 on the system. Additionally, you can also install its extensions on your system. The method to install and uninstall PHP 8 on Ubuntu 22.04 is demonstrated in this post.