How to install PHP 7.x on CentOS 7.x x64

The current version of  in the  7 official repositories is PHP 5.4, which has reached its end of life and is no longer maintained (in terms of bug fixes and critical updates) by the developers. You may be exposed to unpatched vulnerabilities if you are still using it.

epel-release.noarch

wget http://rpms.famillecollet.com/enterprise/remi-release-7.

rpm -Uvh remi-release-7*.rpm

If you already have EPEL installed:

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

Enabling the Repo

Now we need to make sure the repo is enabled and select which version you want to install. We need to head over to /etc/yum.repos.d you should inside see a called remi.repo.

Open the file in your favourite editor (Nano, Pico, Vi etc), you’ll see a number of sections. We need to make sure that the first section [remi] is enabled:

vi /etc/yum.repos.d/remi.repo

[remi]
name=Remi’s RPM repository for Enterprise 7 – $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/remi/httpsmirror
mirrorlist=http://.remirepo.net/enterprise/7/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

 

Note the line enabled=1 make sure this is set! Now technically you can actually go ahead and install PHP, but you will only get PHP 5.4.*. Which might be want to you want is so skip ahead to the next section!

If we want PHP 5.5 or PHP 5.6 we need to do a bit more work, further down in the repo.repo file you will see two additional sections [remi-php55] and [remi-php56], decide which PHP version you want to install and then enable the correct. So for PHP 7.2 we would change to:

vi /etc/yum.repos.d/remi-php72.repo

[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

Installing PHP

sudo yum install php php-gd php- php-mcrypt

As you can see PHP is installing version php-7.2.6-1.el7.remi.x86_64 from the remi-php72 repo! Once you have hit Y to confirm the install restart and magical unicorns you have a better version of PHP!

You can also change your mind in the future by going back into the remi.repo file and enable a different PHP version and then run yum update and if you have moved from 5.5 to 5.6 it will upgrade PHP for you. If you want to downgrade for any reason you will need to remove PHP (sudo yum remove php*) and then reinstall the PHP modules you want.

You can install composer on centos 7 with php 7.x

sudo yum install composer
Print Friendly, PDF & Email

Comments

comments

Bài viết liên quan

1 Trackback / Pingback

  1. How to Install Invoice Ninja on CentOS - Góc IT

Để lại lời nhắn