The main way to install PHP on CentOS is to compile the source or use yum. In my case, I used to compile mainly, but I’ve been using yum mainly because of the fact that RPM-based installation is more convenient and better for performance optimization. Is very low, so you often use an external RPM repository).
Popular repositories that provide the latest version of PHP include webtatic and remi . The main use of webtatic was changed to remi during the upgrade to PHP 7.2. The reason I chose remi is as follows.
- webtatic does not support mcrypt (removed as a security issue in PHP 7.2).
- We recommend using openssl or libsodium for webtatic
- If you need it , use phpseclib / mcrypt_compat ( search for mcrypt in packagist, there are other projects)
- See: PHP 7.2.1 on CentOS / RHEL 7.4 via Yum
- Provide various extensions than webtatic
- Operational services required additional gearman, oci8, etc.
- Quick update
- In the case of webtatic, the update to the latest version is often a little late.
The reasons listed above aren’t all that important, and while alternatives exist, they’ve been replaced for ease of use. In fact, the reason I’ve seen other repositories is due to mcrypt. Although the module is not recommended to be used for security reasons, the module provided by PG (Payment Agent) requires mcrypt, so it has to be used.
It’s been a long time, but let’s look at the installation in earnest (installing using yum is very simple).
- CentOS 7.2
- You must be using the Extra Packages for Enterprise Linux ( EPEL ) repository.
First, add the remi repository to yum.
rpm -Uvh epel-release-latest-7.noarch.rpm
rpm -Uvh remi-release-7.rpm
yum install -y yum-utils
yum-config-manager --enable remi-php72
2. Uninstall your existing PHP installation and install version 7.2
yum remove -y `yum list installed | cut -d "" -f 1 | grep php`
yum list installed | cut -d " " -f 1 | grep phpIt’s a good idea to run the command first before running any of the above commands to determine which packages will be deleted (so that the wrong package is not deleted).
yum install -y php-common php-fpm php-cli \
php-opcache php-pecl-apcu \
php-mysqlnd php-pdo \
php-mbstring php-xml \
php-pecl- zip \
Instead of “php-common”, you can use a package that specifies a PHP version, such as “php72w-common”. Use this method if you need to use a specific version rather than always using the latest version. This method is more secure because future versions of PHP may cause compatibility issues with running programs. However, it is inconvenient to use the method of deleting and installing the existing package during the major version upgrade.
If you already have PHP installed with yum and the package name starts with “php-” (unless you have installed a package that starts with “php72w-” as described above), you can delete and reinstall the existing package as shown below. There is also a way to get updates.
yum update php-*
In my case, I used webtatic before, so I started installing packages with names starting with “php70w-“. Instead, you have installed packages that begin with “php-“, so you can use the update method for future upgrades.
3. Check installed php version
PHP 7.2.2 (cli) (built: Jan 30 2018 13:44:49) (NTS)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.2, Copyright (c) 1999-2018, by Zend Technologies
The installation of PHP using yum is very simple, as shown earlier. Choose whether to install the “php-” package or the “php72w-” package, depending on your management preferences (this is more important than you think).