How to Install PHP 8.2 for Nginx on CentOS 7

To install PHP on CentOS 7 with Nginx, follow these steps.

Step 1 : Ensure your system is up to date:

Step 2 : Install the Remi repository which provides updated PHP versions:

Step 3 : Enable the PHP 8.2 module from the Remi repository:

Step 4 : Install PHP Core

Step 5 : Install Additional PHP Extensions

Explanations:

- php-cli: Command-line interface for PHP.

- php-mysqlnd: MySQL Native Driver for PHP.

- php-curl: cURL extension for PHP.

- php-gd: GD Graphics Library for image manipulation.

- php-mcrypt: Mcrypt extension for PHP (deprecated in PHP 7.1 and removed in PHP 7.2).

- php-json: JSON extension for PHP.

- php-pear: PHP Extension and Application Repository.

- php-common: Common files for PHP.

- php-xml: XML extension for PHP.

- php-zip: Zip extension for PHP.

- php-devel: Development files for PHP.

- php-xsl: XSL extension for PHP.

- php-soap: SOAP extension for PHP.

- php-bcmath: BCMath Arbitrary Precision Mathematics extension for PHP.

- php-mbstring: Multibyte String extension for PHP.

- php-gettext: Gettext extension for PHP.

- php-imagick: Imagick extension for PHP (provides object-oriented interface to ImageMagick).

Step 6 : Edit the PHP-FPM configuration to adjust for Nginx:

Find and update the following lines:

Step 7 : Enable and Start PHP-FPM

Step 8 : Verify PHP Version

Step 9 : Create or edit the Nginx configuration file for your site. For example, edit the example configuration:

Inside this file, configure Nginx to process PHP files. A basic example configuration might look like this:

Step 10 : Test the Nginx configuration for any syntax errors:

Step 11 : Apply the changes by restarting Nginx:

Step 12 : Test PHP

- Create a PHP info file to verify installation:

Add the following content:

Step 13 : View PHP Info in Browser

Visit http://example.com/info.php to see PHP configuration details.

Congratulations! You have successfully installed PHP 8.2 for Nginx on CentOS 7.