CentOS 7和RHEL 7 上 PHP 7.0, 7.1, 7.2的安装

As we know that PHP is the most important part of LAMP applications (WordPress, Joomla, Drupal & Media wiki etc). Now a days most of these applications require PHP 7 for their installation and configuration. Main advantage of PHP 7.x is that it will load your web application faster and will consume less server’s resources like CPU and RAM.

By default, PHP 5.4 is available in CentOS 7 and RHEL 7 yum repositories.  In this article we will demonstrate how to install latest version of PHP on CentOS 7 and RHEL 7 Servers.

Installation Steps of PHP 7.0, 7.1 & 7.2 on CentOS 7 Server

1) Install yum-utils and enable EPEL repository

Login to your server and use the below yum command to install yum-utils & enable epel repository

[root@linuxtechi ~]# yum install epel-release yum-utils -y

2) Download and Install remirepo using yum command

[root@linuxtechi ~]# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

3)  Base on your requirement, configure the PHP 7.x repository

To configure PHP 7.0 repository, use below command,

[root@linuxtechi ~]# yum-config-manager --enable remi-php70

To configure PHP 7.1 repository, use below command,

[root@linuxtechi ~]# yum-config-manager --enable remi-php71

To configure PHP 7.2 repository, use below command

[root@linuxtechi ~]# yum-config-manager --enable remi-php72

4) Install PHP 7.2 along with dependencies.

In this tutorial, I will install latest version of PHP 7.2 along with its modules, Run beneath yum command

[root@linuxtechi ~]# yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

Note: To search all PHP modules use  below command:

[root@linuxtechi ~]# yum search php | more

5) Verify the PHP version

Once all the PHP 7.2 and its dependencies are installed in step4), use below command to verify the installed PHP version,

[root@linuxtechi ~]# php -v
PHP 7.2.7 (cli) (built: Jun 20 2018 08:21:26) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.7, Copyright (c) 1999-2018, by Zend Technologies

Installation Steps of PHP 7.x on RHEL 7 Server

1) Enable EPEL, RHEL 7 Server Optional repository and Install remirepo rpm

Login to your RHEL 7 Server and run the beneath commands one after the another to enable EPEL repository, install remirepo and enable RHEL 7 Server optional repository

[root@linuxtechi ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@linuxtechi ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@linuxtechi ~]# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm 
[root@linuxtechi ~]# subscription-manager repos --enable=rhel-7-server-optional-rpms

2) Configure PHP 7.x repo

[root@linuxtechi ~]# yum install yum-utils
[root@linuxtechi ~]# yum-config-manager --enable remi-php72

3) Install PHP 7.2 and its dependencies

[root@linuxtechi ~]# yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

4) Verify PHP Version

[root@linuxtechi ~]# php -v

PHP 7 Test Page Verification

I am assuming Apache web Server is installed on your system, start its service using below systemctl command

[root@linuxtechi ~]# systemctl start httpd
[root@linuxtechi ~]#

Now create a info.php file under /var/www/html with following contents,

[root@linuxtechi ~]# cd /var/www/html/
[root@linuxtechi html]# vi info.php
<?php
phpinfo();
?>

Open the web browser and type the ip of your server followed by info.php,

http://Server-IP-Address/info.php

This confirms that you have successfully installed PHP 7.2.7 on your system. That’s all from this article, please do share your feedback and comments.

扩展

安装php mysql扩展

yum install php72-php-mysqlnd

安装php72-fpm

yum install php72-php-fpm

启动php72-fpm

使用systemctl来管理php72-fpm

systemctl enable php72-php-fpm.service

Use systemctl command:

sudo systemctl enable php72-php-fpm.service

Sample outputs:

Created symlink from /etc/systemd/system/multi-user.target.wants/php72-php-fpm.service to /usr/lib/systemd/system/php72-php-fpm.service.

启动/停止/重启/查看状态

systemctl start php72-php-fpm.service
systemctl stop php72-php-fpm.service
systemctl restart php72-php-fpm.service
systemctl status php72-php-fpm.service

参考

https://www.cyberciti.biz/faq/how-to-install-php-7-2-on-centos-7-rhel-7/

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *