CentOSRHEL Based

How To Install PHP on CentOS Stream 9

Install PHP on CentOS Stream 9

In this tutorial, we will show you how to install PHP on CentOS Stream 9. PHP 8.3 represents a significant update in the PHP language, introducing new features and improvements that enhance web development capabilities. For CentOS Stream 9 users, installing PHP 8.3 requires specific steps due to its absence in the default repositories.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the PHP scripting language on CentOS Stream 9.

Prerequisites

  • A server running one of the following operating systems: CentOS Stream 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection.
  • You’ll need administrative privileges or root access on your CentOS Stream 9 system. If you don’t have them, reach out to your system administrator.

Install PHP on CentOS Stream 9

Step 1. First, update your system’s package repository to get the latest versions and dependencies:

sudo dnf clean all
sudo dnf update

This command will update all the installed packages on your CentOS system.

Step 2. Installing PHP 8.3 on CentOS Stream 9.

PHP 8.3 is not available in the default CentOS 9 repositories. You’ll need to enable the Remi repository, a third-party repository that provides newer versions of PHP.

The EPEL repository contains additional packages for Enterprise Linux and is a prerequisite for the Remi repository. Install it using the following command:

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

Next, install the Remi repository to gain access to PHP 8.3 packages:

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

 To prevent conflicts with the system’s default PHP version, reset the PHP module:

sudo dnf module reset php

 Enable the PHP 8.3 module from the Remi repository to prepare for installation:

sudo dnf module enable php:remi-8.3

Now install PHP 8.3 along with some common extensions:

sudo dnf install php php-cli php-fpm php-json php-common php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json

Once the PHP is installed, you can check the PHP version on your system with the following command:

php -v

Step 3. Configuration.

After installation, configure PHP and PHP-FPM (FastCGI Process Manager) based on your web server setup (Apache or Nginx).

Edit the php.ini file to customize PHP settings:

sudo nano /etc/php.ini

Start and enable PHP-FPM for better performance with your web server:

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

Step 4. Testing PHP Installation.

Create a PHP file to test the installation:

echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

Access this file from your web browser to see all PHP configuration settings.

Congratulations! You have successfully installed PHP. Thanks for using this tutorial to install the PHP scripting language on CentOS Stream 9. For additional help or useful information, we recommend you check the official PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button