How to Install PHP 8.2 for Nginx on Rocky Linux 9

To install PHP on Rocky Linux 9, follow these detailed steps.

Step 1 : Update

Step 2 : Import PHP Remi Repository

Step 3 : Check PHP Modules

Step 4 : Enable PHP Remi Repository

Step 5 : Install PHP

Step 6 : Install common PHP extensions for various functionalities.

  • php-fpm: Efficiently handles PHP requests using FastCGI.
  • php-cli: Provides a command-line interface for running PHP scripts.
  • php-mysqlnd: Offers a native driver for improved MySQL compatibility and performance.
  • php-curl: Enables cURL support for making HTTP requests.
  • php-gd: Supports the GD Graphics Library for dynamic image creation.
  • php-mcrypt: Deprecated in later PHP versions, provides encryption algorithms.
  • php-json: Facilitates working with JSON-encoded data.
  • php-pear: Includes the PEAR package manager for managing PHP packages.
  • php-common: Contains shared resources and configuration files.
  • php-xml: Provides support for XML parsing and manipulation.
  • php-zip: Enables support for working with Zip archives.
  • php-devel: Includes files and tools for PHP extension development.
  • php-xsl: Provides support for XSL (eXtensible Stylesheet Language).
  • php-soap: Enables support for the SOAP protocol.
  • php-bcmath: Supports arbitrary precision mathematics.
  • php-mbstring: Handles multibyte character encodings.
  • php-gettext: Enables Gettext internationalization functions.
  • php-imagick: Integrates the ImageMagick library for image manipulation.

Step 7 : Modify www.conf

Edit the www.conf file to replace the user and group values with "nginx"

Step 8 : Enable and start the PHP-FPM service.

Step 9 : Verify PHP Version

Check the installed PHP version.

Step 10 : Configure Nginx to Use PHP

- Open your Nginx server block configuration file for your domain using a text editor.

- Add a location block inside the server block to handle PHP files.

Step 11 : Check the Nginx configuration for syntax errors.

Step 12 : Apply the changes by restarting the Nginx service.

Step 13 : Create a simple PHP file for testing.

Step 14 : View PHP Info

Open your web browser and navigate to http://example.com/info.php to view PHP information.

Congratulations! You have successfully installed PHP 8.2 for Nginx on Rocky Linux 9.