How to Install the Latest Version of PHP (8.x) on Ubuntu: A Step-by-Step Guide

PBC Media
3 min readJul 23, 2023
Install PHP on UBUNTU

PHP, one of the most widely used programming languages for web development, continues to evolve with each new version, bringing enhanced features, improved performance, and increased security. The latest major release, PHP 8.x, introduces several exciting improvements and optimizations. If you’re an Ubuntu user looking to upgrade to PHP 8.x, this article will guide you through the installation process. By following the step-by-step instructions below, you’ll be up and running with the latest PHP version on your Ubuntu machine in no time.

Explain Ubuntu

Ubuntu is a popular Linux-based operating system known for its stability, security, and user-friendly interface. It is an open-source platform that provides a solid foundation for developers and users alike. Ubuntu is widely adopted for web servers, making it an excellent choice for hosting PHP applications. Its robust package management system and strong community support make it easier to install and manage the latest software versions.

Ubuntu vs. Windows vs. Mac (Chart):

Ubuntu vs. Windows vs. Mac (Chart)

Step 1: Update System Packages

Before we begin, let’s ensure that our system is up to date. Open the terminal and run the following command to update the package lists and upgrade existing packages:

sudo apt-get update && sudo apt-get upgrade

The system will prompt you to enter your password. Type your password (no characters will be displayed) and press Enter.

Step 2: Add Ondřej Surý’s PHP PPA

Next, we need to add the PHP Personal Package Archive (PPA) maintained by Ondřej Surý, a well-known PHP developer. This PPA provides up-to-date PHP packages for Ubuntu. Run the following commands in the terminal to add the PPA:

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

Enter your password when prompted and press Enter. While you add the PHP PPA, a prompt will ask you to confirm adding the PPA. So, Press Enter when prompted to confirm adding the PPA.

Step 3: Install PHP 8.x

With the PPA added, we can now install PHP 8.x. Run the following command to install PHP and its necessary dependencies:

sudo apt-get install php8.2

If a prompt asked to confirm the installation or do you want to continue? Enter ‘Y’ and press Enter to confirm the installation.

Step 4: Verify the Installation

To ensure that PHP 8.x has been successfully installed, we can verify the version by running the following command:

php -v

You should see the PHP version displayed, confirming the installation.

Step 5: Optional — Installing Additional PHP Extensions

Depending on your project requirements, you may need to install additional PHP extensions. The following command installs some commonly used extensions, but feel free to adjust it based on your specific needs:

sudo apt install php8.2-{extension-name}

Replace `{extension-name} ` with the name of the desired extension. For example, to install the JSON extension, use `php8.2-json`.

Step 6: Configuring PHP

By default, PHP 8.x is configured with reasonable defaults. However, you might need to make some adjustments based on your project’s requirements. The PHP configuration files are located in the `/etc/php/8.2/` directory. Edit the desired configuration file using your preferred text editor.

Step 7: Testing PHP

To ensure that PHP is functioning correctly, create a test file named `info.php` in your web server’s root directory with the following content:

<?php
phpinfo();
?>

Save the file and access it through a web browser by visiting `http://localhost/info.php`. If PHP is working correctly, you should see a page displaying detailed information about your PHP installation.

Updating to the latest version of PHP is crucial for leveraging the newest features, performance improvements, and security enhancements. With the step-by-step guide provided above, you can easily install PHP 8.x on your Ubuntu machine. Remember to always keep your software stack up to date to ensure optimal performance, security, and compatibility with modern web development practices. Happy coding with PHP 8.x!

--

--

PBC Media

Highly qualified technical writer | Simplifying complex concepts | Software Development background | Technical expertise and exceptional writing skills.