How to Install PHP 8 on Ubuntu

In this article, we'll guide you through the process of installing PHP 8 on your Ubuntu system. PHP 8, the latest major release of the PHP programming language, introduces significant performance improvements and new features. By upgrading to PHP 8 on Ubuntu, you can tap into these enhancements and ensure compatibility with modern PHP applications.

Throughout the following sections, we'll provide you with a step-by-step guide to install PHP 8 on Ubuntu. We'll cover the necessary commands and configurations for a smooth installation.

So, let's begin and learn how to install PHP 8 on Ubuntu, including options like installing PHP 8.2 on Ubuntu or PHP 8.1, and addressing issues like PHP command not found on Ubuntu 22.04.

Step 1: Add PHP Repository

PHP 8 is not available in the default Ubuntu repositories. To install PHP 8, we need to add a repository that provides the PHP 8 packages. Open a terminal window and run the following commands to add the ondrej/php repository

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


Step 2: Update Package Lists

After adding the repository, update the package lists to include the PHP 8 packages. Run the following command.

sudo apt update


Step 3: Install PHP 8

Now, you can proceed to install PHP 8 and the necessary extensions. Run the following command to install PHP 8 along with commonly used extensions.

sudo apt install php8.0 php8.0-cli php8.0-fpm php8.0-mysql php8.0-gd php8.0-xml php8.0-curl php8.0-mbstring

During the installation process, you may be prompted to confirm the installation and dependencies. Type 'Y' and press Enter to proceed.


Step 4: Verify PHP Installation

To verify that PHP 8 is installed correctly, run the following command to check the PHP version.

php -v


You might also like: