Home Linux CentOS How To Install PHP 7.0, PHP 7.1 and PHP 7.2 on CentOS...

How To Install PHP 7.0, PHP 7.1 and PHP 7.2 on CentOS 7

500
0

Using an obsolete PHP version is clearly not recommended, especially for a web hosting environment. However, in some cases you might encounter compatibility issues with your web software system requirements with a PHP version you’re using, which ultimately requires you to use an older PHP7 version. Now, several PHP7 versions have and will reach its End-Of-Lives (EOL), including PHP 7.0 and PHP 7.1.

In this tutorial we will guide you on how to install PHP 7.0, PHP 7.1 and PHP 7.2 on a CentOS 7 server. So don’t panic, we can still use the old PHP7 version on our CentOS 7 server. Simply follow this guide to install it on your server.

1.) Update System and Software Packages

$ yum update -y
$ yum install wget nano screen telnet zip unzip -y

2.) Install EPEL and REMI RPM’s Repository for CentOS 7

Just like setting up PHP 7.3 on CentOS 7, we should add EPEL and REMI RPM’s Repository to your system in order to install PHP 7.0, PHP 7.1 and PHP 7.2.

$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
$ yum --enablerepo=remi update remi-release

3.) Install PHP 7.0, PHP 7.1 and 7.2 along with Its Dependencies

Now, let’s install desired old PHP7+ version along with its dependencies. Below we’ve provide you some different command to install old PHP7 version. So, you can choose to install PHP 7.0, PHP 7.1 and PHP 7.2 with the Apache (HTTPD) server or Nginx web server + PHP FastCGI Process Manager (PHP-FPM).

READ:  Creating a New Sudo User on CentOS 8, The Easy Way

* For PHP 7.0 with Apache (HTTPD)

$ yum --enablerepo=remi-php70 install php70-php php70-php-pear php70-php-bcmath php70-php-pecl-jsond-devel php70-php-mysqlnd php70-php-gd php70-php-common php70-php-intl php70-php-cli php70-php php70-php-xml php70-php-opcache php70-php-pecl-apcu php70-php-pecl-jsond php70-php-pdo php70-php-gmp php70-php-process php70-php-pecl-imagick php70-php-devel php70-php-mbstring php70-php-soap php70-php-mcrypt php-mcrypt php-soap phpMyAdmin roundcubemail memcached php70-php-pecl-memcached php70-php-pecl-memcache php-opcache php-redis redis php70-php-redis php71-php-zip php71-php-pspell php-brotli

* For PHP 7.0 with FastCGI Process Manager (FPM)

$ yum --enablerepo=remi-php70 install php70-php php70-php-pear php70-php-bcmath php70-php-pecl-jsond-devel php70-php-mysqlnd php70-php-gd php70-php-common php70-php-fpm php70-php-intl php70-php-cli php70-php php70-php-xml php70-php-opcache php70-php-pecl-apcu php70-php-pecl-jsond php70-php-pdo php70-php-gmp php70-php-process php70-php-pecl-imagick php70-php-devel php70-php-soap php70-php-mcrypt php-mcrypt php-soap php70-php-mbstring phpMyAdmin roundcubemail memcached php70-php-pecl-memcached php70-php-pecl-memcache php-redis redis php70-php-redis php71-php-zip php71-php-pspell php-brotli

* For 7.1 with Apache (HTTPD)

$ yum --enablerepo=remi-php71 install php71-php php71-php-pear php71-php-bcmath php71-php-pecl-jsond-devel php71-php-mysqlnd php71-php-gd php71-php-common php71-php-intl php71-php-cli php71-php php71-php-xml php71-php-opcache php71-php-pecl-apcu php71-php-pecl-jsond php71-php-pdo php71-php-gmp php71-php-process php71-php-pecl-imagick php71-php-devel php71-php-mbstring php71-php-soap php71-php-mcrypt php-mcrypt php-soap phpMyAdmin roundcubemail memcached php71-php-pecl-memcached php71-php-pecl-memcache php-opcache php-redis redis php71-php-redis php71-php-zip php71-php-pspell php-brotli

* For PHP 7.1 with FastCGI Process Manager (FPM)

$ yum --enablerepo=remi-php71 install php71-php php71-php-pear php71-php-bcmath php71-php-pecl-jsond-devel php71-php-mysqlnd php71-php-gd php71-php-common php71-php-fpm php71-php-intl php71-php-cli php71-php php71-php-xml php71-php-opcache php71-php-pecl-apcu php71-php-pecl-jsond php71-php-pdo php71-php-gmp php71-php-process php71-php-pecl-imagick php71-php-devel php71-php-soap php71-php-mcrypt php-mcrypt php-soap php71-php-mbstring phpMyAdmin roundcubemail memcached php71-php-pecl-memcached php71-php-pecl-memcache php-redis redis php71-php-redis php71-php-zip php71-php-pspell php-brotli

* For PHP 7.2 with Apache (HTTPD)

$ yum --enablerepo=remi-php72 install php72-php php72-php-pear php72-php-bcmath php72-php-pecl-jsond-devel php72-php-mysqlnd php72-php-gd php72-php-common php72-php-intl php72-php-cli php72-php php72-php-xml php72-php-opcache php72-php-pecl-apcu php72-php-pecl-jsond php72-php-pdo php72-php-gmp php72-php-process php72-php-pecl-imagick php72-php-devel php72-php-mbstring php72-php-soap php72-php-mcrypt php-mcrypt php-soap phpMyAdmin roundcubemail memcached php72-php-pecl-memcached php72-php-pecl-memcache php-opcache php-redis redis php72-php-redis php72-php-zip php72-php-pspell php-brotli

* For PHP 7.2 with FastCGI Process Manager (FPM)

$ yum --enablerepo=remi-php72 install php72-php php72-php-pear php72-php-bcmath php72-php-pecl-jsond-devel php72-php-mysqlnd php72-php-gd php72-php-common php72-php-fpm php72-php-intl php72-php-cli php72-php php72-php-xml php72-php-opcache php72-php-pecl-apcu php72-php-pecl-jsond php72-php-pdo php72-php-gmp php72-php-process php72-php-pecl-imagick php72-php-devel php72-php-soap php72-php-mcrypt php-mcrypt php-soap php72-php-mbstring phpMyAdmin roundcubemail memcached php72-php-pecl-memcached php72-php-pecl-memcache php-redis redis php72-php-redis php72-php-zip php72-php-pspell php-brotli

4.) Edit php.ini Files

After we’ve successfully install Old PHP7, we need to edit php.ini file to fix some values, depending on PHP7 version you’re using.

READ:  How To Fix Missing Kernel-Headers on CentOS 7

* For Apache/HTTPD:

$ nano /etc/php.ini
$ nano /etc/opt/remi/php70/php.ini
$ nano /etc/opt/remi/php71/php.ini
$ nano /etc/opt/remi/php72/php.ini
$ session.save_handler = files
$ session.save_path = /var/lib/php/session
$ soap.wsdl_cache_dir ="/tmp"

* For PHP-FPM:

$ nano /etc/php.ini
$ nano /etc/opt/remi/php70/php.ini
$ nano /etc/opt/remi/php71/php.ini
$ nano /etc/opt/remi/php72/php.ini
$ session.save_handler = files
$ session.save_path = /var/lib/php/session
$ soap.wsdl_cache_dir = /var/lib/php/wsdlcache

After that, set correct directory permission for PHP session

$ chmod 777 /var/lib/php/session/

5.) Check PHP Version

You can check PHP version with the following commands.

$ php -v
$ php70 -v
$ php71 -v
$ php72 -v

6.) PHP 7.0, PHP 7.1 and PHP 7.2 with FastCGI Process Manager (FPM)

This is important step if you have configured Old PHP7 with FastCGI Process Manager (FPM). In order to make Old PHP7-FPM work seamlessly on CentOS 7, we need to create symbolic link for each PHP7 version. You can use one of the following commands, depending on Old PHP7 version you’re using.

Create Symbolic Link for PHP 7.0, PHP 7.1 and PHP 7.2

$ rm -f /usr/bin/php

For PHP 7.0:

$ ln -s /usr/bin/php70 /usr/bin/php

For PHP 7.1:

$ ln -s /usr/bin/php71 /usr/bin/php

For PHP 7.2:

$ ln -s /usr/bin/php72 /usr/bin/php

7.) Remove Old PHP-FPM Systemd Service File and Link to New One

After that, don’t forget to remove Old PHP-FPM Systemd Service File from your CentOS 7 system and then create symlink to desired PHP7-FPM version.

$ rm -f /usr/lib/systemd/system/php-fpm.service

For PHP 7.0:

$ ln -s /usr/lib/systemd/system/php70-php-fpm.service /usr/lib/systemd/system/php-fpm.service

For PHP 7.1:

$ ln -s /usr/lib/systemd/system/php71-php-fpm.service /usr/lib/systemd/system/php-fpm.service

For PHP 7.2:

$ ln -s /usr/lib/systemd/system/php72-php-fpm.service /usr/lib/systemd/system/php-fpm.service

8.) Reload Systemd Manager Configuration

$ systemctl daemon-reload

9. Restart Apache / Nginx and PHP-FPM

Depending on your web server type, you need to restart the following services.

$ service httpd restart
$ service nginx restart
$ service php-fpm start

LEAVE A REPLY

Please enter your comment!
Please enter your name here