How to install latest PHP on a CentOS 7 server

To install PHP 7, you have to install and enable EPEL and Remi repository to your CentOS 7 system with the commands below.

sudo rpm -Uvh
sudo rpm -Uvh
sudo rpm -Uvh

Next, you need to install yum-utils, a collection of useful programs for managing yum repositories and packages.

yum install yum-utils

To install PHP 7.2 on CentOS 7, just enable it as shown

yum-config-manager --enable remi-php72

Now install PHP 7 with all necessary modules with the command below.

yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo php-common

Afterwards, double check the installed version of PHP on your system.

php -v

We need to restart the Apache web server in order for it to work with PHP

sudo systemctl restart httpd

In CentOS 7, this directory is located at /var/www/html/. We can create the file at that location by typing:

sudo nano /var/www/html/info.php

This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:


When you are finished, save and close the file.The address you want to visit will be:


If this was successful, then your PHP is working as expected.
You probably want to remove this file after this test because it could actually give information about your server to unauthorized users. To do this, you can type this:

sudo rm /var/www/html/info.php
Leave a reply

Sharing is caring!

Back to Top