How to guides and technology tutorials for Amazon AWS, Google Cloud, Linux, macOS, Windows, and other systems

How to install PHP on CentOS

Published: 18 January 2017
Updated: 29 April 2020
Filed Under: CentOS

Using Yum on CentOS will by default, install an older release of PHP. In order to install the latest version of PHP, you will need to enable the EPEL and Remi repositories and install the correct PHP software. If you are planning on migrating code from PHP 5, keep in mind that PHP 7 has many changes and may break your code.

CentOS 7

sudo yum install
sudo yum install
sudo yum install yum-utils
sudo yum-config-manager --enable remi-php74
sudo yum update
sudo yum install php php-cli

CentOS 8

Installing PHP 7.4 on CentOS is a little different, and also requires you to enable the PHP-FPM dependency.

sudo dnf install
sudo dnf install
sudo dnf module reset php
sudo dnf module enable php:remi-7.4
sudo dnf update
sudo dnf install php php-cli
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Check version

Confirm the PHP version installed with the command below.

php --version