CentOS7.5 install PHP7.3 using yum

Keywords: PHP yum RPM vim

1. Install php

Current system environment

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@localhost ~]# uname -sr
Linux 4.16.11-1.el7.elrepo.x86_64

Install yum source

php 7 has two yum sources to choose from, one is webmatic and the other is remi.

Add webmatic source (not accessible, not used)

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Add remi source
Because I can't access the webmatic source here, I use the remi source

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum clean all && yum makecache

View installable versions of php

[root@localhost ~]# yum list | grep php7 | more
 * remi-php73: mirror.innosol.asia
mod_php72u.x86_64                         7.2.8-1.ius.centos7          @ius     
php72u-common.x86_64                      7.2.8-1.ius.centos7          @ius     
php73.x86_64                              1.0-0.1.el7.remi             @remi-safe
php73-php-cli.x86_64                      7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-common.x86_64                   7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-fpm.x86_64                      7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-gd.x86_64                       7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-json.x86_64                     7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-ldap.x86_64                     7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-mbstring.x86_64                 7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-mysqlnd.x86_64                  7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-opcache.x86_64                  7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-pdo.x86_64                      7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-pecl-mysql.x86_64               1.0.0-0.19.20180226.647c933.el7.remi
php73-php-snmp.x86_64                     7.3.0~alpha4-1.el7.remi      @remi-safe
php73-php-xml.x86_64                      7.3.0~alpha4-1.el7.remi      @remi-safe
php73-runtime.x86_64                      1.0-0.1.el7.remi             @remi-safe
mod_php70u.x86_64                         7.0.31-1.ius.centos7         ius      
mod_php71u.x86_64                         7.1.20-1.ius.centos7         ius      
...........................

Select the corresponding version to install. Install php7.3 here

# yum install –y php73

To view the file directory:

[root@localhost ~]# find / -name php
/var/opt/remi/php73/lib/php
/opt/remi/php73/root/usr/bin/php
/opt/remi/php73/root/usr/lib64/php
/opt/remi/php73/root/usr/share/php

Import environment variables

[root@localhost ~]# vim /etc/profile
PATH=$PATH:/opt/remi/php73/root/usr/bin
export PATH
[root@localhost ~]# source /etc/profile

View php version

[root@localhost ~]# php -v
PHP 7.3.0alpha4 (cli) (built: Jul 17 2018 14:06:14) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies

2. Install php extension

yum install –y php73-php-mysql php73-php-snmp php73-php-xml php73-php-ldap php73-php-gd php73-php-mbstring php73-php-fpm

3. Install the mod_php module

This module supports running PHP as an Apache module. mod_php73 is not found here. Install mod_php72u directly
View version

[root@localhost ~]# yum list | grep mod_php
mod_php72u.x86_64                         7.2.8-1.ius.centos7          @ius     
mod_php70u.x86_64                         7.0.31-1.ius.centos7         ius      
mod_php71u.x86_64                         7.1.20-1.ius.centos7         ius  

Execution and installation

[root@localhost ~]# yum install -y mod_php72u
Installed:
  mod_php72u.x86_64 0:7.2.8-1.ius.centos7 

Check the directory / etc/httpd/modules / for two more files (omitted here for httpd installation, just install by yourself)

[root@localhost ~]# ll /etc/httpd/modules/
total 13288
-rwxr-xr-x 1 root root 5124368 Jul 20 01:06 libphp7.so
-rwxr-xr-x 1 root root 5313928 Jul 20 01:06 libphp7-zts.so

Configure the httpd.conf file, load the libphp7.so module, and add the following at the end of the file

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
....
LoadModule php7_module        /usr/lib64/httpd/modules/libphp7.so

Create a php page and test the php environment,

[root@localhost ~]# vim /var/www/html/index.php 
<?php
    phpinfo();
?>

Restart httpd service and test

# systemctl restart httpd 

Access server address http://192.168.92.56

Why is it 7.2.8, not 7.3? This is just an experimental environment test, please do not use it in the production environment easily!

Posted by freddykhalid on Sun, 05 Jan 2020 13:12:07 -0800