Table of Contents
Since we recently posted an article about downgrading from PHP 7.2 to PHP 7.1 on CentOS, we thought that it could be useful to add a post explaining how to install it in the first place. As a matter of fact, it's not as easy as typing sudo yum install php on our linux terminal window, as the PHP build officially supported on CentOS 7.4 is still PHP 5.6.
Step 1: Add the Repository
The first thing we need to do is to add the proper repository to our CentOS machine. In order to do that, navigate to the /etc/yum.repos.d/ folder and add one of the following files, depending if you want to install PHP 7.0 , PHP 7.1 or PHP 7.2:
PHP 7.0
This file contains the URLs pointing to the Remi's RPM Repository for PHP 7.0. For this very reason, we suggest to call this file remi-php70.repo or something like that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# This repository only provides PHP 7.0 and its extensions # NOTICE: common dependencies are in "remi-safe" [remi-php70] name=Remi's PHP 7.0 RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/php70/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/php70/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/php70/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php70-debuginfo] name=Remi's PHP 7.0 RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-php70/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php70-test] name=Remi's PHP 7.0 test RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/test70/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/test70/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/test70/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php70-test-debuginfo] name=Remi's PHP 7.0 test RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-test70/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi |
PHP 7.1
This file contains the URLs pointing to the Remi's RPM Repository for PHP 7.1. For this very reason, we suggest to call this file remi-php71.repo or something like that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# This repository only provides PHP 7.1 and its extensions # NOTICE: common dependencies are in "remi-safe" [remi-php71] name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/php71/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/php71/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-debuginfo] name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-php71/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-test] name=Remi's PHP 7.1 test RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/test71/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/test71/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/test71/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-test-debuginfo] name=Remi's PHP 7.1 test RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-test71/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi |
PHP 7.2
This file contains the URLs pointing to the Remi's RPM Repository for PHP 7.2. For this very reason, we suggest to call this file remi-php72.repo or something like that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# This repository only provides PHP 7.1 and its extensions # NOTICE: common dependencies are in "remi-safe" [remi-php71] name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/php71/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/php71/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-debuginfo] name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-php71/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-test] name=Remi's PHP 7.1 test RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/test71/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/test71/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/test71/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-test-debuginfo] name=Remi's PHP 7.1 test RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-test71/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi# This repository only provides PHP 7.2 and its extensions # NOTICE: common dependencies are in "remi-safe" [remi-php72] name=Remi's PHP 7.2 RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/php72/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/php72/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/php72/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php72-debuginfo] name=Remi's PHP 7.2 RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-php72/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php72-test] name=Remi's PHP 7.2 test RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/test72/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/test72/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/test72/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php72-test-debuginfo] name=Remi's PHP 7.2 test RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-test72/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi |
Step 2: Enable the Repository
Now that we added the repository, we need to ensure that our CentOS machine will ask us to fetch the PHP version we want to install. To do that, we have to enable the corresponding repository using one of the commands below:
For PHP 7.0
1 |
# yum-config-manager --enable remi-php70 |
For PHP 7.1
1 |
# yum-config-manager --enable remi-php71 |
For PHP 7.2
1 |
# yum-config-manager --enable remi-php72 |
Step 3: Install PHP
As soon as we added the proper repository by creating the .repo file in the /etc/yum.repos.d/ folder, we can proceed with the standard yum install command: as our CentOS machine will automatically find the proper repo:
1 |
# sudo yum install php php-mcrypt php-cli php-gd php-curl php-mysqlnd php-ldap php-zip php-fileinfo |
Needless to say, you can add (or remove) any other php extension you might want to setup for your system, such as: php-soap, php-pecl-zip and so on.
If we did everything correctly, we'll have PHP installed on our CentOS machine in less than a minute.