PHPLinux VPSUbuntu

How to Install PHP 8.0 on Ubuntu: A Comprehensive Guide

In our previous post, “How to Installing PHP 7.4 on Ubuntu: A Comprehensive Guide,” we took you through the detailed process of installing PHP 7.4, a version known for its stability and performance improvements. Building on that knowledge, it’s time to explore the installation of a newer PHP version, PHP 8.0, which brings even more exciting features and enhancements to the table. This comprehensive guide will walk you through the step-by-step process of installing PHP 8.0 on your Ubuntu system.

If you haven’t read our previous posts on PHP installation, we recommend checking them out for a more in-depth understanding of the process.

Prerequisites:

Before we begin the installation process, make sure you have the following prerequisites in place:

  1. An Ubuntu server or desktop system (This guide is based on Ubuntu 20.04 LTS, but the process should be similar for other versions).
  2. Access to a terminal with administrative privileges. You can use the terminal emulator or SSH for this purpose.

Now, let’s dive into the installation of PHP 8.0.

Step 1: Update Your System

As always, it’s a good practice to ensure your system is up to date before installing any software. Open your terminal and execute the following commands:

sudo apt update

This command refreshes the package information on your Ubuntu system, ensuring your package manager has the latest data on available packages and their versions from the configured software repositories.

Next, perform a system upgrade to keep your installed packages up to date:

sudo apt upgrade

The sudo apt upgrade command will search for updates to your installed packages and prompt you to confirm any available upgrades. Regularly running this command is essential to maintain your system with the latest software updates and security patches.

Step 2: Add a PPA Repository

To manage multiple PHP versions, we’ll use the Ondřej Surý PPA repository, which provides a range of PHP versions, including PHP 8.0. Before adding this repository, you need to install the software-properties-common package, which provides useful tools for managing external repositories:

sudo apt install software-properties-common

Once software-properties-common is installed, add the Ondřej Surý PPA repository:

sudo add-apt-repository ppa:ondrej/php

After adding the repository, update your package list:

sudo apt update

Step 3: Install PHP Version 8.0

You will need some knowledge of PHP to install the PHP version. In your case you may need different PHP versions. But from our previous post we get the idea that PHP vs PHP-FPM. If you haven’t seen my previous post, click here

To install PHP 8.0 FPM, you’d run:

sudo apt install php8.0-fpm

Or if you don’t want to install PHP-FMP version then follow this command:

sudo apt install php8.0

This command will download and install PHP 8.0, along with any necessary dependencies. Confirm the installation by typing “Y” when prompted.

Step 4: Install PHP Extensions

Just like with previous PHP versions, PHP extensions are essential to enhance the functionality of your PHP installation. You can use the apt package manager to install these extensions. Here’s an example of how to install the MySQL extension for PHP 8.0:

sudo apt install php8.0-mysql

You can replace mysql with the name of the extension you need. Some common PHP extensions for PHP 8.0 include gd for GD graphics library, curl for cURL support, xml for XML support, libapache2 for apache2  and json for JSON support. You can install multiple extensions in one command by listing them with spaces.

sudo apt install php8.0-cli libapache2-mod-php8.0 php8.0-common php8.0-curl php8.0-mbstring php8.0-opcache php8.0-readline php8.0-xml php8.0-zip php8.0-mysql php8.0-gd

Step 5: Switching Between PHP Versions

To switch between PHP versions, use the update-alternatives command. For example, to set PHP 8.0 as the active version, run:

sudo update-alternatives --set php /usr/bin/php8.0

To confirm the active PHP version, you can use the php -v command:

php -v

Step 6: Configuring Web Servers

If you’re running web applications, you’ll also need to configure your web server to use the desired PHP version. For Apache, you can enable PHP for a specific version with:

Disable your current PHP version and then enable PHP 8.2 for the Apache server.

Here are the corrected commands:

For example, if your current PHP version is PHP 7.4:

sudo a2dismod php7.4

And then enable PHP 8.0 for the Apache server:

sudo a2enmod php8.0

For Nginx, you’ll need to configure your Nginx virtual host files to use PHP 8.0.

Conclusion

In this comprehensive guide, we’ve walked you through the step-by-step process of installing PHP 8.0 on your Ubuntu system. PHP 8.0 comes with exciting features and improvements, making it a great choice for web development projects. By following these steps, you can have PHP 8.0 up and running on your Ubuntu machine, ready to power your web applications.

If you encounter any questions or issues during the installation process, please refer to our previous posts for a more in-depth understanding of PHP installation on Ubuntu.

Happy Coding!

IQBAL HASAN

I love to talk on trending ⚡ technology ⚡, I have huge attraction on 😁 Linux 😅 and I am a bit 😄 mad 😄 when I code.

Related Articles

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button