How To Install PHP 8.2 on Ubuntu 20.04

In this tutorial, we want to teach you How To Install PHP 8.2 on Ubuntu 20.04.

PHP is an open-source server-side scripting language that many devs use for web development. It is also a general-purpose language that you can use to make lots of projects, including Graphical User Interfaces (GUIs).

PHP 8.2 brings type-system improvements for expressive and fine-grained type-safety, readonly classes, sensitive parameter redaction support, new random extension, and many new features along with several changes to streamline and modernize PHP language.

Steps To Install PHP 8.2 on Ubuntu 20.04

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 20.04.

In this guide, you will learn to install PHP 8.2 with Apache and Nginx Modules.

Import Ondřej Surý PHP PPA on Ubuntu 20.04

To successfully install PHP 8.2, you will need to import the good renowned PPA from Ondřej Surý, the lead developer on PHP and Debian, and maintain Ubuntu and Debian packages.

To install Ondřej Surý PPA and the required packages on Ubuntu 20.04, run the following command:

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

Then, update  and upgrade your local package index with the command below:

sudo apt update && sudo apt upgrade

Set up PHP 8.2 on Ubuntu 20.04

At this point, you can install PHP 8.2 with an Apache option and an Nginx option.

Installing PHP 8.2 for Apache on Ubuntu 20.04

If you run an Apache HTTP server, you can run PHP as an Apache module or PHP-FPM.

To install PHP 8.2 as an Apache module, enter the following command on Ubuntu 20.04:

sudo apt install php8.2 libapache2-mod-php8.2 -y

When your installation is completed, restart Apache for the new PHP module to be loaded:

sudo systemctl restart apache2

Also, you can install Apache with PHP-FPM. To do this, run the following command:

sudo apt install php8.2-fpm libapache2-mod-fcgid
Enable PHP-FPM for Apache on Ubuntu 20.04

Note: PHP-FPM is not enabled for Apache. You must enable it by the following command:

sudo a2enmod proxy_fcgi setenvif && sudo a2enconf php8.2-fpm

Restart Apache to apply the changes:

sudo systemctl restart apache2

Verify that your PHP-FPM service is active and running on your server:

sudo systemctl status php8.2-fpm
Output
● php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; vendor pr>
     Active: active (running) since Sun 2022-12-25 12:35:20 CET; 41s ago
       Docs: man:php-fpm8.2(8)
    Process: 10975 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /ru>
   Main PID: 10972 (php-fpm8.2)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req>
      Tasks: 3 (limit: 4620)
     Memory: 7.5M
     CGroup: /system.slice/php8.2-fpm.service
             ├─10972 php-fpm: master process (/etc/php/8.2/fpm/php-fpm.conf)
             ├─10973 php-fpm: pool www
             └─10974 php-fpm: pool www
...

You can verify your PHP installation on Ubuntu 20.04, with the command below:

php --version
Output
PHP 8.2.0 (cli) (built: Dec 10 2022 10:52:42) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies

Installing PHP 8.2 for Nginx on Ubuntu 20.04

Nginx does not contain native PHP processing like some other web servers like Apache. You will need to install PHP-FPM “fastCGI process manager” to handle the PHP files.

Install PHP 8.2 and PHP 8.2-FPM on Ubuntu 20.04 with the following command:

sudo apt install php8.2 php8.2-fpm php8.2-cli -y

Verify your PHP-FPM service is active and running on your server with the command below:

sudo systemctl status php8.2-fpm
Output
● php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; vendor pr>
     Active: active (running) since Sun 2022-12-25 12:35:20 CET; 1min 52s ago
       Docs: man:php-fpm8.2(8)
    Process: 10975 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /ru>
   Main PID: 10972 (php-fpm8.2)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req>
      Tasks: 3 (limit: 4620)
     Memory: 7.5M
     CGroup: /system.slice/php8.2-fpm.service
             ├─10972 php-fpm: master process (/etc/php/8.2/fpm/php-fpm.conf)
             ├─10973 php-fpm: pool www
             └─10974 php-fpm: pool www

Also, you need to edit your Nginx server block and add the example below for Nginx to process the PHP files on Ubuntu 20.04.

server {
# … some other code
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}

Test Nginx to make sure you have no errors with the adjustments made with the code above; enter the following command:

sudo nginx -t
Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
nginx: configuration file /etc/nginx/nginx.conf test is successful

Then, restart Nginx to apply the changes:

sudo systemctl restart nginx

Also, you can verify your PHP 8.2 installation on Ubuntu 20.04:

php --version
Output
PHP 8.2.0 (cli) (built: Dec 10 2022 10:52:42) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies

Conclusion

At this point, you learn to Install PHP 8.2 on Ubuntu 20.04.

Hope you enjoy it.

You may be like these articles from the Orcacore website:

How To Install Sysdig on Ubuntu 20.04

How To List Users and Groups in Linux

How To Find a spam script on cPanel

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular