After I showed last week what problems you can deal with when switching from PHP 5.6 to PHP 7, I would like to show you how to switch to PHP 7 at all. Since I am now migrating to CentOS with all servers, it will be the first time that it is not a Debian example. The good thing about CentOS is that it is a fairly stable distribution – every major release is supported for 10 years. The bad thing about CentOS is that many packages are in a fairly old version, which is only provided with bug and security fixes. In my web server installations, I would rather rather operate new versions to get new features.
When you install a newer version, you have several options: either compiling PHP 7 yourself or using a third repository that contains pre-compiled packages for PHP 7. In this case I have decided for the second. With ius.io there is a repository for CentOS 7, which contains the most important packages and should be maintained for a long time due to the support of the host rackspace .
To use the IUS repository, you must first install your RPM package, which takes care of configuring the repository in the system:
yum install wget yum install epel-release wget https://centos7.iuscommunity.org/ius-release.rpm sudo rpm -i ./ius-release.rpm rm ./ius-release.rpm
Update 05/21/2020: link changed to https://repo.ius.io/ius-release-el7.rpm and not support php7.1 you must use php72u or php73
yum install wget yum install epel-release wget https://repo.ius.io/ius-release-el7.rpm sudo rpm -i ./ius-release-el7.rpm rm ./ius-release-el7.rpm
Result:
[root@tutorialspots ~]# yum install wget Loaded plugins: fastestmirror base | 3.6 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 (1/4): base/7/x86_64/group_gz | 155 kB 00:01 (2/4): extras/7/x86_64/primary_db | 191 kB 00:01 (3/4): base/7/x86_64/primary_db | 5.6 MB 00:01 (4/4): updates/7/x86_64/primary_db | 7.8 MB 00:01 Determining fastest mirrors * base: mirrors.linode.com * extras: mirrors.linode.com * updates: mirrors.linode.com Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-13.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: wget x86_64 1.14-13.el7 base 546 k Transaction Summary ================================================================================ Install 1 Package Total download size: 546 k Installed size: 2.0 M Is this ok [y/d/N]: y Downloading packages: wget-1.14-13.el7.x86_64.rpm | 546 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : wget-1.14-13.el7.x86_64 1/1 Verifying : wget-1.14-13.el7.x86_64 1/1 Installed: wget.x86_64 0:1.14-13.el7 Complete!
[root@tutorialspots ~]# yum install epel-release Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.linode.com * extras: mirrors.linode.com * updates: mirrors.linode.com Resolving Dependencies --> Running transaction check ---> Package epel-release.noarch 0:7-9 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: epel-release noarch 7-9 extras 14 k Transaction Summary ================================================================================ Install 1 Package Total download size: 14 k Installed size: 24 k Is this ok [y/d/N]: y Downloading packages: epel-release-7-9.noarch.rpm | 14 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : epel-release-7-9.noarch 1/1 Verifying : epel-release-7-9.noarch 1/1 Installed: epel-release.noarch 0:7-9 Complete!
[root@tutorialspots ~]# wget https://centos7.iuscommunity.org/ius-release.rpm --2017-07-24 10:24:24-- https://centos7.iuscommunity.org/ius-release.rpm Resolving centos7.iuscommunity.org (centos7.iuscommunity.org)... 2001:4802:7801: 102:be76:4eff:fe21:14aa, 162.242.221.48 Connecting to centos7.iuscommunity.org (centos7.iuscommunity.org)|2001:4802:7801 :102:be76:4eff:fe21:14aa|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release -1.0-15.ius.centos7.noarch.rpm [following] --2017-07-24 10:24:26-- https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86 _64/ius-release-1.0-15.ius.centos7.noarch.rpm Resolving dl.iuscommunity.org (dl.iuscommunity.org)... 2001:4802:7901:0:4ccc:ff1 1:0:a, 146.20.25.47 Connecting to dl.iuscommunity.org (dl.iuscommunity.org)|2001:4802:7901:0:4ccc:ff 11:0:a|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 8340 (8.1K) [application/x-redhat-package-manager] Saving to: `ius-release.rpm' 100%[======================================>] 8,340 --.-K/s in 0s 2017-07-24 10:24:27 (71.5 MB/s) - `ius-release.rpm' saved [8340/8340]
In my case I install besides PHP synonymous always equal MariaDB and NGINX. The IUS repository also contains a more recent version of MariaDB. In order to install these, however, you must first remove the existing “mariadb-libs”. In the process, Postfix is also uninstalled – we will simply reinstall it afterwards:
yum remove mariadb-libs
Result:
[root@tutorialspots ~]# yum remove mariadb-libs Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be erased --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix- 2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for pa ckage: 2:postfix-2.10.1-6.el7.x86_64 --> Running transaction check ---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: mariadb-libs x86_64 1:5.5.52-1.el7 @anaconda 4.4 M Removing for dependencies: postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M Transaction Summary ================================================================================ Remove 1 Package (+1 Dependent package) Installed size: 17 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2 Erasing : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2 Verifying : 2:postfix-2.10.1-6.el7.x86_64 1/2 Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2 Removed: mariadb-libs.x86_64 1:5.5.52-1.el7 Dependency Removed: postfix.x86_64 2:2.10.1-6.el7 Complete!
Now we can install the desired software via the software administration – packages that are installed via IUS always contain the suffix “u” to make them easier to recognize and avoid collisions with standard packages:
yum install mariadb101u-server nginx php71u-cli php71u-fpm php71u-gd php71u-imap php71u-intl php71u-json php71u-ldap php71u-mbstring php71u-mcrypt php71u-mysqlnd php71u-pdo php71u-pear php71u-pgsql php71u-process php71u-pspell php71u-recode php71u-soap php71u-xml php71u-xmlrpc postfix
Update 05/21/2020
yum install mariadb101u-server nginx php73-cli php73-fpm php73-gd php73-imap php73-intl php73-json php73-ldap php73-mbstring php73-mcrypt php73-mysqlnd php73-pdo php73-pear php73-pgsql php73-process php73-pspell php73-recode php73-soap php73-xml php73-xmlrpc postfix
Result:
... Installed: mariadb101u-server.x86_64 1:10.1.24-1.ius.centos7 nginx.x86_64 1:1.10.2-1.el7 php71u-cli.x86_64 0:7.1.7-1.ius.centos7 php71u-fpm.x86_64 0:7.1.7-1.ius.centos7 php71u-gd.x86_64 0:7.1.7-1.ius.centos7 php71u-imap.x86_64 0:7.1.7-1.ius.centos7 php71u-intl.x86_64 0:7.1.7-1.ius.centos7 php71u-json.x86_64 0:7.1.7-1.ius.centos7 php71u-ldap.x86_64 0:7.1.7-1.ius.centos7 php71u-mbstring.x86_64 0:7.1.7-1.ius.centos7 php71u-mcrypt.x86_64 0:7.1.7-1.ius.centos7 php71u-mysqlnd.x86_64 0:7.1.7-1.ius.centos7 php71u-pdo.x86_64 0:7.1.7-1.ius.centos7 php71u-pgsql.x86_64 0:7.1.7-1.ius.centos7 php71u-process.x86_64 0:7.1.7-1.ius.centos7 php71u-pspell.x86_64 0:7.1.7-1.ius.centos7 php71u-recode.x86_64 0:7.1.7-1.ius.centos7 php71u-soap.x86_64 0:7.1.7-1.ius.centos7 php71u-xml.x86_64 0:7.1.7-1.ius.centos7 php71u-xmlrpc.x86_64 0:7.1.7-1.ius.centos7 postfix.x86_64 2:2.10.1-6.el7 Dependency Installed: aspell.x86_64 12:0.60.6.1-9.el7 fontconfig.x86_64 0:2.10.95-10.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 gd.x86_64 0:2.0.35-26.el7 gperftools-libs.x86_64 0:2.4-8.el7 libX11.x86_64 0:1.6.3-3.el7 libX11-common.noarch 0:1.6.3-3.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXpm.x86_64 0:3.5.11-3.el7 libaio.x86_64 0:0.3.109-13.el7 libc-client.x86_64 0:2007f-4.el7.1 libicu.x86_64 0:50.1.2-15.el7 libjpeg-turbo.x86_64 0:1.2.90-5.el7 libmcrypt.x86_64 0:2.5.8-13.el7 libpng.x86_64 2:1.5.13-7.el7_2 libtool-ltdl.x86_64 0:2.4.2-22.el7_3 libunwind.x86_64 2:1.1-5.el7_2.2 libxcb.x86_64 0:1.11-4.el7 libxslt.x86_64 0:1.1.28-5.el7 mariadb101u.x86_64 1:10.1.24-1.ius.centos7 mariadb101u-common.x86_64 1:10.1.24-1.ius.centos7 mariadb101u-config.x86_64 1:10.1.24-1.ius.centos7 mariadb101u-errmsg.x86_64 1:10.1.24-1.ius.centos7 mariadb101u-libs.x86_64 1:10.1.24-1.ius.centos7 nginx-all-modules.noarch 1:1.10.2-1.el7 nginx-filesystem.noarch 1:1.10.2-1.el7 nginx-mod-http-geoip.x86_64 1:1.10.2-1.el7 nginx-mod-http-image-filter.x86_64 1:1.10.2-1.el7 nginx-mod-http-perl.x86_64 1:1.10.2-1.el7 nginx-mod-http-xslt-filter.x86_64 1:1.10.2-1.el7 nginx-mod-mail.x86_64 1:1.10.2-1.el7 nginx-mod-stream.x86_64 1:1.10.2-1.el7 php71u-common.x86_64 0:7.1.7-1.ius.centos7 postgresql-libs.x86_64 0:9.2.18-1.el7 recode.x86_64 0:3.6-38.el7 rsync31u.x86_64 0:3.1.2-2.ius.centos7 Complete!
Basically one is now finished at this point and has its CentOS 7 equipped with PHP 7. In my case, however, there were a few more things to do, as I needed SSH support in my PHP. Since there is still no ready-made package for IUS (probably because the SSH support for PHP 7 is not yet stable ), I had to compile the extension myself.
To do this, we have to install additional, required packages:
yum install autoconf automake make openssl-devel php71u-devel unzip zip
Update 05/21/2020
yum install autoconf automake make openssl-devel php73-devel unzip zip
Result:
... Installed: autoconf.noarch 0:2.69-11.el7 automake.noarch 0:1.13.4-3.el7 openssl-devel.x86_64 1:1.0.1e-60.el7_3.1 php71u-devel.x86_64 0:7.1.7-1.ius.centos7 unzip.x86_64 0:6.0-16.el7 zip.x86_64 0:3.0-11.el7 Dependency Installed: keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.14.1-27.el7_3 libcom_err-devel.x86_64 0:1.42.9-9.el7 libkadm5.x86_64 0:1.14.1-27.el7_3 libselinux-devel.x86_64 0:2.5-6.el7 libsepol-devel.x86_64 0:2.5-6.el7 libverto-devel.x86_64 0:0.2.5-4.el7 m4.x86_64 0:1.4.16-10.el7 pcre-devel.x86_64 0:8.32-15.el7_2.1 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Test-Harness.noarch 0:3.28-3.el7 perl-Thread-Queue.noarch 0:3.02-2.el7 zlib-devel.x86_64 0:1.2.7-17.el7 Dependency Updated: krb5-libs.x86_64 0:1.14.1-27.el7_3 openssl.x86_64 1:1.0.1e-60.el7_3.1 openssl-libs.x86_64 1:1.0.1e-60.el7_3.1 Complete!
Install gcc if it doesn’t exist:
yum install gcc
Result:
... Installed: gcc.x86_64 0:4.8.5-11.el7 Dependency Installed: cpp.x86_64 0:4.8.5-11.el7 glibc-devel.x86_64 0:2.17-157.el7_3.5 glibc-headers.x86_64 0:2.17-157.el7_3.5 kernel-headers.x86_64 0:3.10.0-514.26.2.el7 libmpc.x86_64 0:1.0.1-3.el7 mpfr.x86_64 0:3.1.1-4.el7 Dependency Updated: glibc.x86_64 0:2.17-157.el7_3.5 glibc-common.x86_64 0:2.17-157.el7_3.5 Complete!
Next, fetch, compile, and install the current version of the “libssh2” library:
wget https://www.libssh2.org/download/libssh2-1.7.0.tar.gz tar -xzvf ./libssh2-1.7.0.tar.gz cd ./libssh2-1.7.0 ./configure make sudo make install make clean cd .. rm ./libssh2-1.7.0.tar.gz rm -Rf ./libssh2-1.7.0
On Github someone has made the effort to set up the sources for PHP 7 compileable – its changes will also be the basis for the future SSH module. To this Github repository I hanged myself and compiled everything myself. As soon as the stabilized packages with IUS was taken, one should of course switch to this:
wget https://github.com/Sean-Der/pecl-networking-ssh2/archive/master.zip unzip ./master.zip cd ./pecl-networking-ssh2-master phpize ./configure make sudo make install make clean cd .. rm ./master.zip rm -Rf ./pecl-networking-ssh2-master sudo sh -c "echo 'extension=ssh2.so' >/etc/php.d/20-ssh2.ini"
And you have already installed PHP 7 on your CentOS 7 and is still bleading-edge on the road.
Now start Nginx service , PHP-fpm service and Mariadb service.
systemctl enable nginx systemctl enable php-fpm systemctl enable mariadb service nginx start service php-fpm start service mariadb start
More: config nginx to run PHP file
location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_connect_timeout 250; fastcgi_send_timeout 250; fastcgi_read_timeout 250; fastcgi_buffer_size 256k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; }