The CentOS 7 official software repositories have PHP 5.4 which has reached the end of life and no longer actively maintained by the developers.
To keep up with the latest features and security updates, you need a newer (probably the latest) version of PHP on your CentOS 7 system.
For the purpose of this guide, we will be operating the system as root, if that is not the case for you, make use of the sudo command to acquire root privileges.
Installing PHP 7 on CentOS 7
1. To install PHP 7, you have to install and enable EPEL and Remi repository on your CentOS 7 system with the commands below.
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2. Next, you need to install yum-utils, a collection of useful programs for managing yum repositories and packages. It has tools that basically extend yum’s default features.
It can be used for managing (enabling or disabling) yum repositories as well as packages without any manual configuration and so much more.
# yum install yum-utils
3. One of the programs provided by yum-utils is yum-config-manager, which you can use to enable Remi repository as the default repository for installing different PHP versions as shown.
# yum-config-manager --enable remi-php70 [Install PHP 7.0]
If you want to install PHP 7.1, PHP 7.2 or PHP 7.3 on CentOS 7, just enable it as shown.
# yum-config-manager --enable remi-php71 [Install PHP 7.1] # yum-config-manager --enable remi-php72 [Install PHP 7.2] # yum-config-manager --enable remi-php73 [Install PHP 7.3]
4. 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
Afterwards, double check the installed version of PHP on your system.
# php -v

Lastly, below is a list of useful PHP articles that you can read for additional information:
- How to Use and Execute PHP Codes in Linux Command Line
- How to Find MySQL, PHP and Apache Configuration Files
- How to Test PHP MySQL Database Connection Using Script
- How to Run PHP Script as Normal User with Cron
In this article, we have explained how to install PHP 7 on CentOS 7 Linux. You can send us any questions or additional thoughts via the feedback form below.
I have a problem in the third step when I entered the code of PHP 7.3 then it shown the message command not found.
@Divesh,
Install yum-utils to package to get yum-config-manager command…
Hey,
Maybe a stupid question. But how can we start and restart PHP without rebooting the server?
When we do [systemctl restart php74] results in Failed to restart php74.service: Unit not found.
When we do [systemctl | grep php] not a single result is returned. Is php74.service not running? Or is it part of something else cause we installed it with the yum manager or something?
Regards Jerome.
@Jerome,
PHP is a just programming language that doesn’t have a service to start, you just need to restart the Apache or Nginx webserver to reflect changes you made to any configuration files of PHP.
When running command :
yum-config-manager --enable remi-php70
this results, is this okay?
Hey, how to Remove the PHP installed by this tutorial, I used this tutorial to install PHP 7.2 and now I wanted to remove it, It Not showing in Package On in ->
What is the Solution ?
@Ganesh
If it’s the default PHP version on your system, then simply run: