🐧

Centos 8

2 notes  •  Linux & Server Admin

Install PHP on CentOS 8 / RHEL 8

How to install PHP on CentOS 8 or RHEL 8 using the AppStream repository or the Remi repository for newer versions.

Method 1 — Install from AppStream (Default)

sudo dnf install -y php php-cli php-fpm php-mysqlnd php-json php-opcache \
    php-xml php-mbstring php-gd php-curl php-zip

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

Method 2 — Install a Specific PHP Version via Remi Repository

# Install EPEL and Remi repo
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

# List available PHP streams
sudo dnf module list php

# Enable PHP 8.1
sudo dnf module reset php
sudo dnf module enable php:remi-8.1

# Install PHP 8.1
sudo dnf install -y php php-cli php-fpm php-mysqlnd php-xml php-mbstring php-gd php-zip php-opcache
php -v

Configure PHP-FPM with Nginx

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

# PHP-FPM socket location
ls /run/php-fpm/www.sock

Verify

php -v
php -m | grep -E "mysql|opcache|gd|curl"
sudo systemctl status php-fpm

Install PHP 7.3 on CentOS 8 / RHEL 8

How to install PHP 7.3 on CentOS 8 or RHEL 8 using the Remi repository.

Step 1 — Add EPEL and Remi Repositories

sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Step 2 — Enable PHP 7.3 Stream

sudo dnf module reset php
sudo dnf module enable php:remi-7.3

Step 3 — Install PHP 7.3 and Extensions

sudo dnf install -y php php-cli php-common php-fpm \
    php-mysqlnd php-xml php-mbstring php-gd php-curl \
    php-zip php-opcache php-json

Step 4 — Start PHP-FPM

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

Verify

php -v
# Should show: PHP 7.3.x
php -m
sudo systemctl status php-fpm