How to Install PHP 8 on Ubuntu 20.04 LTS

  • Last update: Apr 3, 2024
  • Views: 43
  • Author: Admin
How to Install PHP 8 on Ubuntu 20.04 LTS

Hello colleagues.

The PHP programming language is one of the most widely used server side programming languages. It is a language used to develop dynamic and responsive websites. The latest version of PHP today is PHP version 8. In this version you will find many new features to help you improve your application.

By default, the Ubuntu 20.04 repositories contain the PHP 7.4 language version, and in order for us to install the latest version of PHP, we will need to use the Ondrej PPA repository.

 

Article content:

  1. Installing dependencies.
  2. Adding the Ondrej PPA repository.
  3. Install PHP 8.
  4. Restart Apache.
  5. Checking the PHP installation.
  6. Apache with PHP-FPM.
  7. Installing the PHP extension.

 

1. Install dependencies.

The first thing we will start with is installing the necessary dependencies, for this we will execute the command:

$. sudo apt install ca-certificates apt-transport-https software-properties-common

ubuntu install php8


 

2. Adding the Ondrej PPA repository.

After installing the dependencies, we now need to install the  Ondrej PPA repository in our Ubuntu, for this we need to run the command:

$. sudo add-apt-repository ppa:ondrej/php


 

3. PHP 8 installation.

I use Apache webserver on my server, so I install PHP 8 with Apache module. If you have an Nginx web server, then the process is slightly different there.

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

ubuntu install php8

Confirm the installation of PHP with the Y key and press Enter.


 

4. Restart Apache.

After installing PHP, you need to restart the Apache web server in order for all the necessary modules to run.

$. sudo systemctl restart apache2


 

5. Checking the PHP installation.

Now we can check how PHP was installed and what version, for this we will execute the php command:

$. php -v

ubuntu install php8

As you can see from the screenshot, we now have PHP version 8 installed, as we wanted.


 

6. Apache with PHP-FPM.

You can also install PHP-FPM if you like. PHP-FPM is a FastCGI process manager for PHP. Run the following command to install the required packages:

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

 

PHP-FPM is not enabled by default in Apache. To enable it run:

$. sudo a2enmod proxy_fcgi setenvif

$. sudo a2enconf php8.0-fpm

ubuntu install php8

After enabling PHP-FPM, be sure to restart the Apache web server.

$. systemctl reload apache2


 

7. Installing the PHP extension.

If you do not have enough functionality, then you can still install special extensions provided by PHP. Extensions in PHP are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed using apt.

Syntax:

$. sudo apt install php8.0-<extension>

Example:

$. sudo apt install php8.0-cli php8.0-common php8.0-xml


 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES