Redhat 7 (RHEL) install PHP

This article will show you how to install PHP on RHEL 7 and test installation with Nginx server.

Update PHP repo

RHEL 7 default PHP repo only allows you to install old version PHP (5), you’ll need to upgrade your PHP version if you decide to install some ready to use PHP apps such as wordpress, Joomla, etc.

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

# Enable PHP repo
sudo yum-config-manager --enable remi-php74

# You can specify PHP version you need to install repository, for example, to install PHP 7.4 , type below
sudo yum install https://rpms.remirepo.net/enterprise/7/php74/x86_64/php-7.4.26-1.el7.remi.x86_64.rpm

Install PHP version you need

yum --enablerepo=remi-php74 install php

# Install widely used plugins for PHP
yum --enablerepo=remi-php74 install php-fpm php-mysqlnd php-zip php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json

# Verify PHP version by typing
php -v

Enable php-fpm, visit official website for more details

sudo systemctl enable --now php-fpm

Test your PHP installation with Nginx server

Create a index.php file under your nginx web content folder (/usr/share/nginx/html), add below code to this file.

<?php phpinfo(); ?>

You may need to update your nginx config file (/etc/nginx/nginx.conf) to allow index.php file to be accessible. Visit your website/index.php to verify PHP installation information, you should have detailed PHP information displayed on that page.

Reference.

Remi repository

PHP official website

Leave a Comment

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


The reCAPTCHA verification period has expired. Please reload the page.

Scroll to Top