How to Install PHP 8 on Ubuntu

0 comment 3 mins read


Installing PHP 8 on Ubuntu 20.04 and combining it with Nginx and Apache is covered in detail here.

Among server-side languages, PHP has the most widespread use. PHP is used to create a wide variety of content management systems and frameworks.

The one of the current stable version of PHP is 8.0. It adds several new features, including named arguments, a JIT compiler, union types, a match expression, and more, as well as a number of breaking changes and improved efficiency.

In the time of this writing, PHP 7.4 may be found in the default Ubuntu 20.04 repository. Now we’ll use the ondrej/php PPA repository to install PHP.

Make sure your software is compatible with PHP 8 before updating or installing it.

All Ubuntu-based distributions, including Kubuntu, Linux Mint, and Elementary OS, follow the same procedures as described here, not only Ubuntu 18.04.

Enabling PHP Repository

A Debian developer by the name of Ondej Sur runs a repository that contains a number of different PHP distributions. In order to activate the repository, type:

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

Once the PPA is enabled, you can install PHP 8.

Installing PHP 8.0 with Apache

PHP may be used as either an Apache module or PHP-FPM while the Apache web server is in use.

You Might Be Interested In

Install PHP as Apache Module

Installation of PHP as an Apache module is a simple process:

sudo apt update
sudo apt install php8.0 libapache2-mod-php8.0

After the packages have been installed, Apache must be restarted so that the PHP module can be loaded.

sudo systemctl restart apache2

Configure Apache with PHP-FPM

Php-FPM is a PHP-specific FastCGI process manager. Execute the command below to install the required packages:

sudo apt update
sudo apt install php8.0-fpm libapache2-mod-fcgid

Apache is not configured to use PHP-FPM by default. To enable it, run:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm

To apply the modifications, restart Apache:

systemctl restart apache2

Installing PHP 8.0 with Nginx

There is no built-in capability for parsing PHP files in Nginx. PHP-FPM (“fastCGI process manager”) will be used to manage PHP files.

Execute the instructions below to install PHP and PHP FPM packages:

sudo apt update
sudo apt install php8.0-fpm

Once the installation has been finished, the FPM service will immediately begin operating. To determine the status of a service, execute:

systemctl status php8.0-fpm
● php8.0-fpm.service - The PHP 8.0 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.0-fpm.service; enabled; vendor preset:enabled)
     Active: active (running) since Thu 2020-12-03 16:10:47 UTC; 6s ago

To enable Nginx to handle PHP files, you may now modify the Nginx server block and add the following lines:

You Might Be Interested In
server {
    # . . . other code
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;

Restart the Nginx service in order for the new configuration to take effect:

sudo systemctl restart nginx

Installing PHP extensions

PHP extensions are libraries that enhance the capability of PHP’s core. Extensions are available as packages and may be installed simply using apt:

sudo apt install php8.0-[extname]

Execute this command, for instance, to set up MySQL and GD as add-ons:

sudo apt install php8.0-mysql php8.0-gd

Restart the Apache web server or the PHP FastCGI Processor Module (FPM), if appropriate, after installing a new PHP extension.


It doesn’t take much effort to set up PHP 8 on a server running Ubuntu 20.04. Installing PHP 8 with apt is as simple as enabling the “ondrej/php” repository.

Please share your thoughts and questions by posting a comment below.

Leave a Comment

Copyright @2022-2023 All Right Reserved – PCPlanet

Adblock Detected

The only intrusive ad here is the google vignette, help support me by disabling your adblocker.