LinuxRocky

How to Install PHP on Rocky Linux 9

PHP is a popular server-side scripting language widely used for web development. Installing PHP on Rocky Linux 9 is straightforward and can be done using the DNF package manager. This article will guide you through the steps to install PHP on your Rocky Linux 9 system.

Step 1: Update Your System

Before installing any new packages, it’s a good practice to update your system to the latest versions of existing packages.

sudo dnf update -y

Step 2: Enable the EPEL Repository

EPEL (Extra Packages for Enterprise Linux) repository provides additional packages that are not included in the default Rocky Linux repositories.

sudo dnf install epel-release -y

Step 3: Enable the REMI Repository

The REMI repository provides the latest versions of PHP. To install the latest PHP version, you need to enable this repository.

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

Step 4: Install DNF Utils

DNF Utils helps in managing repositories and packages.

sudo dnf install dnf-utils -y

Step 5: Enable the PHP Module Stream

Rocky Linux 9 uses module streams to manage different versions of software like PHP. You can check available PHP module streams with:

sudo dnf module list php

Enable the PHP module of your choice. For example, to enable PHP 8.1:

sudo dnf module enable php:remi-8.1 -y

Step 6: Install PHP

Now, install PHP and some commonly used PHP extensions:

sudo dnf install php php-cli php-common php-mysqlnd php-fpm php-xml php-mbstring php-curl php-json -y

Step 7: Verify PHP Installation

Check the installed PHP version to verify the installation:

php -v

You should see output similar to:

PHP 8.1.x (cli) (built: ...)

Step 8: Configure PHP-FPM (Optional)

If you are using PHP-FPM with a web server such as Nginx, start and enable the PHP-FPM service:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Step 9: Test PHP with a Web Server

If you have Apache or Nginx installed, create a PHP info file to test PHP processing:

  1. Create a file named info.php in your web server’s root directory (e.g., /var/www/html/):
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
  1. Open a web browser and navigate to http://your_server_ip/info.php

You should see a page displaying detailed information about your PHP installation.

Conclusion

You have successfully installed PHP on Rocky Linux 9. You can now develop or deploy PHP-based web applications on your server. Remember to remove the info.php file after testing to avoid exposing sensitive information about your server configuration.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top button