How To Install PHP 8.2 on Centos 7

This guide intends to teach you How To Install PHP 8.2 on Centos 7.

According to PHP Official Page, PHP 8.2 is a major update of the PHP language. It contains many new features, including readonly classes, null, false, and true as stand-alone types, deprecated dynamic properties, performance improvements, and more.

In addition to the exciting new features and improvements, PHP 8.2 streamlines the language by deprecating support for dynamic class properties, warnings when it encounters certain non-optimal INI configuration values, and fixing some of the legacy PHP behavior that affects how PHP sorts arrays and certain types of string transform/encode operations.

Steps To Install PHP 8.2 on Centos 7

Before you start to install PHP 8.2, you need to 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 Centos 7.

Set up PHP 8.2 on Centos 7

First, you need to update your local package index with the command below:

sudo yum update -y

Then, you need to install the Epel repository on Centos 7 with the command below:

sudo yum install epel-release -y

Install Remi Repository on Centos 7

PHP 8.2 is not featured in Centos’s AppStream. So you can install PHP from the (Remi) repository that deploys the latest PHP 8.2 builds. To do this, run the following command:

sudo yum -y install yum-utils https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Update your local package index again:

sudo yum update -y

Remove Previous Version of PHP

Now you need to remove the PHP and PHP-FPM previous versions if you have them installed on your server. To do this, run the following command:

sudo yum remove php php-fpm -y

Then remove the rest of the package extensions with the command below:

sudo yum remove php* -y

Now disable the Remi repository for PHP with the following command:

sudo yum-config-manager --disable 'remi-php*'

Enable PHP 8.2 Remi Repository on Centos 7

Next, you need to enable the Remi for PHP 8.2 on Centos 7 with the following command:

sudo yum-config-manager --enable remi-php82

Run the command below to see if the Remi repository for PHP 8.2 is enabled on your server:

sudo yum repolist

You should get the following output:

Output
remi-php82                                               | 3.0 kB     00:00
remi-php82/primary_db                                      | 161 kB   00:00
repo id          repo name                                                status
base/7/x86_64    CentOS-7 - Base                                          10,072
epel/x86_64      Extra Packages for Enterprise Linux 7 - x86_64           13,730
extras/7/x86_64  CentOS-7 - Extras                                           515
remi-php82       Remi's PHP 8.2 RPM repository for Enterprise Linux 7 - x    271
remi-safe        Safe Remi's RPM repository for Enterprise Linux 7 - x86_  5,091
updates/7/x86_64 CentOS-7 - Updates                                        4,538
repolist: 34,217

Install PHP 8.2 on Centos 7

At this point, you can install PHP 8.2 and some common extensions on Centos 7 with the command below:

sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache,redis,memcache}

To install all the PHP extensions, you can use the following command:

sudo yum install php-xxx

Verify your PHP installation on Centos 7 by checking its version:

php --version
Output
PHP 8.2.0 (cli) (built: Dec  6 2022 14:26:47) (NTS gcc x86_64)
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

Configure PHP-FPM Service

By default on Centos 7, the PHP-FPM service is designed to be run (Apache) user. If you are using Nginx you need to make configuration changes at (www.conf).

You can open the file with your favorite text editor, here we use vi:

sudo vi /etc/php-fpm.d/www.conf

Find the user and group directives and change them to Nginx as shown below:

user = nginx
group = nginx

When you are done, save and close the file.

Reload the PHP-FPM service to apply the changes:

sudo systemctl restart php-fpm

The Nginx server block needs the following example below for Nginx to process the PHP files.

Below is an example for all server {} blocks that process PHP files that need the location ~ .php$ added.

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

For more information, you can visit the PHP Documentation page.

Conclusion

At this point, you have learned to Install PHP 8.2 on Centos 7.

Hope you enjoy it.

You may be interested in these articles:

Install and Use MonoDevelop on Centos 7

Set up DirectAdmin on Centos 7

Install and Use FFmpeg on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!