Install any version of PHP
The official CentOS 7 repositories have PHP 5.4 that has reached the end of its useful life and developers no longer actively maintain it. Next, we will see an example of how to install php 7.0, but we can apply the same procedure for the other versions of php 7.1, php 7.2, php 7.3
To keep up to date with the latest security features and updates, the latest version of PHP is required on your CentOS 7 system so we can avoid future security issues.
For the example below we need root access for the installation of php modules and repositories plus a editor (vim or nano), you can use the editor of your choice.
You can install the nano or vim editor with the following command:
# yum install vim
# yum install vim-nox nano
Install PHP 7.0 on CentOS 7
1. To install PHP 7.0, you must install and enable the EPEL and Remi repository on your CentOS 7 system with the following commands.
# 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 must install yum-utils, a collection of useful programs for managing repositories and yum packages. It has tools that basically extend the default functions of yum. It can be used to manage (enable or disable) yum repositories, as well as packages without any manual configuration.
# yum install yum-utils
3. One of the programs provided by yum-utils is yum-config-manager, which you can use to enable the Remi repository as the default repository for installing different versions of PHP as shown.
# yum-config-manager --enable remi-php70 we enable repositories for (PHP 7.0)
For the installation of PHP 7.1, PHP 7.2 or PHP 7.3 on CentOS 7, we will first have to enable the repositories.
# yum-config-manager --enable remi-php71 (PHP 7.1 )
# yum-config-manager --enable remi-php72 (PHP 7.2 )
# yum-config-manager --enable remi-php73 (PHP 7.3)
Next, we can install PHP 7.0 modules and dependencies with the following command.
yum install php70-php-bcmath php70-php-cli php70-php-common php70-php-fpm php70-php-gd php70-php-intl php70-php-json php70-php -mbstring php70-php-mcrypt php70-php-mysqlnd php70-php-opcache php70-php-pdo php70-php-pear php70-php-pecl-uploadprogress php70-php-pecl-zip php70-php-soap php70-php- xml php70-php-xmlrpcpcache php70-php-pdo php70-php-pear php70-php-pecl-uploadprogress php70-php-pecl-zip php70-php-soap php70-php-xml php70-php-xmlrpc
# php -v
4. We have to restart apache services with the following command:
# systemctl restart httpd
5. We can check the version of php installed in our system
# php -v
If you are interested in modifying the configuration of your version of php you can do it through the directory /etc/opt/remi/php70/php.ini
# vim /etc/opt/remi/php70/php.ini