How to install PHP 8 on CentOS Stream 9

Pre-requisites:

A system with CentOS Stream 9 installed and running
Access to a terminal or command line
Root or sudo privileges

First update your system

dnf update -y

Next, we need to enable the Remi repository

To install PHP 8, we'll need to enable this repository:

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

To check what php versions are available to us, we will want to run:

dnf module list php

Next, enable PHP 8.0 Remi Module

dnf module enable php:remi-8.0

The following command resets the PHP module to its default state. When updating PHP, this is useful to ensure you are starting from a clean slate.

dnf module reset php

Next, install PHP 8 and some common extensions that you may need

dnf install -y 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

After the install, check the php version

php -v

Next, configure php-fpm

Start and enable php-fpm with the following commands:

systemctl start php-fpm

systemctl enable php-fpm

Ensure that php-fpm is running

systemctl status php-fpm

At the time of PHP installation, php.ini is a special file provided as a default configuration file.

To check the file path of php.ini run the command below

find '/' -name "php.ini"

The -name option searches for files with a specific name

Run the following command for PHP information

php -i

Additionally, you could create a sample php file in the /var/www/html folder or your root directory of your web server as shown:

vim /var/www/html/info.php

Then, add the following PHP code which can be used to output a large amount of information about your PHP installation.

<?php 

phpinfo(); 

?>

After saving the file, just point your web browser at it to view its result. For example, open:

http://<server_ip>/info.php

Output a list of command line options with one line descriptions of what they do

php -h

List all installed PHP extensions on a Linux machine

php -m

Learn about general installation considerations on the official website

http://www.php.net/manual/en/install.general.php

Learn about the PHP command line options on the official website

http://www.php.net/manual/en/features.commandline.options.php

For information on the most current stable PHP version on the official website

http://www.php.net/downloads

Learn

Related articles

Getting Started with React

In this guide, we will cover the basics of setting up a local development environment, starting a simple React project, and the basics of how it works.

How to Create Bash Aliases

This tutorial demonstrates how to use the alias command to create personalized shortcuts, which can help you save time and feel less frustrated.

Using Git for PHP Development

This guide walks through the fundamentals of Git. In this tutorial, we will show you Git commands. For Linux you can use the built-in terminal.

How to Connect to MySQL with Laravel

In this guide, you will learn how to connect your Laravel application to your MySQL database.

How do you change the default SSH Port on CentOS Stream 9?

Changing the default SSH port adds an extra layer of security by reducing the risk of your password being cracked from a brute force attack.

What is Inheritance in PHP?

In this tutorial we will explain inheritance in PHP, a mechanism that allows a child class to inherit properties and behaviors from a parent class.