活到老学到老  

记录遇到问题的点点滴滴。

PHP 7.1 on CentOS/RHEL 6.8 and 7.2 via Yum

7年前发布  · 2087 次阅读
  install 

PHP 7.1.1 has been released on PHP.net on 19th January 2017, and is also available for CentOS/RHEL 6.8 and 7.2 at Webtatic via Yum in it’s testing repository.

PEAR installer now supports PHP 7.*, however most pecl libraries will not support it as well without their maintainers adding compatibility, so only pecl libraries that do support it will be in the Webtatic repository.

  • pecl memcache extension – no sign of PHP 7 support development in official source repository
  • pecl memcached extension – PHP 7 support is still in development, and no pre-releases available
  • pecl imagick extension – currently waiting for a fix for the beta3 release

 

PHP 7.1.0 comes with new version of the Zend Engine with features such as (incomplete list):

  • support for a void return type.
  • iterable type hint to encapsulate both array and Traversable objects
  • Closure::fromCallable to convert any callable to a Closure object
  • Session ID without hashing

To see what else has been added, check out PHP 7.1 NEWS.

To install, first you must add the Webtatic EL yum repository information corresponding to your CentOS/RHEL version to yum:

CentOS/RHEL 7.x:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

CentOS/RHEL 6.x:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Now you can install PHP 7.1’s mod_php SAPI (along with an opcode cache) by doing:

yum install mod_php71w php71w-opcache

You can alternatively install PHP 7.1’s php-fpm SAPI (along with an opcode cache by doing:

yum install php71w-fpm php71w-opcache

See the package list below for additional SAPIs and PHP extensions.

This will install the mod_php SAPI for PHP, however there are other sapis such as php-fpm (via php71w-fpm package). Read on below for more information about the available SAPIs

If you would like to upgrade php to this version it is recommended that you first check that your system will support the upgrade, e.g. making sure any CPanel-like software can run after the upgrade.

Unless you know what you are doing, it is risky upgrading an existing system. It’s much safer to do this by provisioning a separate server to perform the upgrade as a fresh install instead.

If you know what you are doing, you can upgrade PHP by:

yum install yum-plugin-replace
 
yum replace php-common --replace-with=php71w-common

It will likely give you a message “WARNING: Unable to resolve all providers …”. This is normal, and you can continue by tying “y“. You will be given a chance to see what packages will be installed and removed before again being given a chance to confirm.

SAPIs – different runtime environments of PHP

mod_php NTS(non-thread safety) Contained in the mod_php71w package, this SAPI integrates into Apache Httpd (2.2.* on RHEL/CentOS 6, 2.4.* on RHEL/CentOS 7). It is the standard SAPI for use with httpd prefork mpm (the default mode httpd is ran under. It is not thread-safe, but doesn’t need to be due to prefork not using threads. It’s located at /usr/lib[64]/httpd/modules/libphp7.socliContained in the php71w-cli package, this SAPI allows running scripts from the command-line, and also has a built-in web server for development-use. Located at /usr/bin/phpfpmContained in the php71w-fpm package, fpm (FastCGI Process Manager) is a scalable FastCGI process, which acts similar to how Httpd prefork mpm works managing it’s forks. Located at /usr/sbin/php-fpm, it is controlled using the /etc/init.d/php-fpm service scriptphpdbgContained in the php71w-phpdbg package, phpdbg has the ability to debug scripts using breakpoints from the command-line, and also supports remote-debugging using an external Java client for remote communication.embeddedContained in the php71w-embedded package, this SAPI allows embedding PHP in other applications. It’s library is located at /usr/lib[64]/libphp7.socgi, fastcgiContained in the php71w-cli package, these SAPIs are not recommended for use, but are available where needed. They both exist in the binary at /usr/bin/php-cgi.mod_php TS(thread safety) Contained in the mod_php71w package, this SAPI integrates into Apache Httpd (2.2.* on RHEL/CentOS 6, 2.4.* on RHEL/CentOS 7). It is the standard SAPI for use with httpd worker mpm. It’s supposed to be thread-safe, but can’t guarantee to be, and certainly not under additional PHP extensions. It’s better to use FastCGI SAPIs than this one. It’s located at /usr/lib[64]/httpd/modules/libphp7-zts.so

Packages

PackageProvides
mod_php71wphp71w, php71w-zts
php71w-bcmath 
php71w-cliphp-cgi, php-pcntl, php-readline
php71w-commonphp-api, php-bz2, php-calendar, php-ctype, php-curl, php-date, php-exif, php-fileinfo, php-filter, php-ftp, php-gettext, php-gmp, php-hash, php-iconv, php-json, php-libxml, php-openssl, php-pcre, php-pecl-Fileinfo, php-pecl-phar, php-pecl-zip, php-reflection, php-session, php-shmop, php-simplexml, php-sockets, php-spl, php-tokenizer, php-zend-abi, php-zip, php-zlib
php71w-dba 
php71w-devel 
php71w-embeddedphp-embedded-devel
php71w-enchant 
php71w-fpm 
php71w-gd 
php71w-imap 
php71w-interbasephp_database, php-firebird
php71w-intl 
php71w-ldap 
php71w-mbstring 
php71w-mcrypt 
php71w-mysqlphp-mysqli, php_database
php71w-mysqlndphp-mysqli, php_database
php71w-odbcphp-pdo_odbc, php_database
php71w-opcachephp71w-pecl-zendopcache
php71w-pdophp71w-pdo_sqlite, php71w-sqlite3
php71w-pdo_dblibphp71w-mssql
php71w-pear 
php71w-pecl-apcu 
php71w-pecl-mongodb 
php71w-pecl-redis 
php71w-pgsqlphp-pdo_pgsql, php_database
php71w-phpdbg 
php71w-processphp-posix, php-sysvmsg, php-sysvsem, php-sysvshm
php71w-pspell 
php71w-recode 
php71w-snmp 
php71w-soap 
php71w-tidy 
php71w-xmlphp-dom, php-domxml, php-wddx, php-xsl
php71w-xmlrpc 

Opcode Caches

The PHP distribution now comes with an opcode cache. This is the Zend Optimizer+ opcode cache, now known as the Zend OPcache extension. This extension is optional, so does not preclude you from using an alternate one.

Due to it being included in the PHP source distribution, it will be well maintained and more suitable for use while other Opcode cache’s are being updated over the coming months.

yum install php71w-opcache

error_reporting E_ALL includes E_STRICT

As mentioned in the PHP 5.4 guide:

You may get a lot more errors coming out of your error logs if by default your error_reporting is set to E_ALL now without explicitly turning off E_STRICT. The default php.ini that comes with the PHP package turns this off by default, but if you are upgrading from an existing installation, your php.ini may not be updated, meaning this will likely be turned on.