CentOS 7 yum 安装 PHP 7.2

标签: none

PHP 7.2可以设置好repo库之后直接用yum安装, 没有特殊需求不需要使用编译安装.

首先安装必要的程序包

yum install epel-release yum-utils
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

启用remi 仓库

yum-config-manager --enable remi-php72
yum update

搜索可以安装的程序

yum search php72 | more
yum search php72 | egrep 'fpm|gd|mysql|memcache'


php72-php-fpm.x86_64 : PHP FastCGI Process Manager
php72-php-gd.x86_64 : A module for PHP applications for using the gd graphics
php72-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL
php72-php-pecl-mysql.x86_64 : MySQL database access functions
php72-php-pecl-mysql-xdevapi.x86_64 : MySQL database access functions

安装PHP 7.2 和必要扩展

yum install php72 php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache php72-php-mcrypt

检查PHP版本

php72 --version
php72 --modules

在nginx 启用PHP

# 检查服务启动参数
cat /etc/systemd/system/multi-user.target.wants/php72-php-fpm.service
# 检查nginx用户组
egrep '^(user|group)' /etc/nginx/nginx.conf
# 创建sock 目录
mkdir -p /var/run/php-fpm/

修改php-fpm 配置

vim /etc/opt/remi/php72/php-fpm.d/www.conf

user = nginx
group = nginx

listen = /var/run/php-fpm/php-fpm.sock

listen.owner = nginx
listen.group = nginx

修改nginx 配置文件

vim /etc/nginx/nginx.conf

server {
    .... # 其他配置参数

    location ~ .php$ {
      fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME $document_root/$fastcgi_script_name;
      include        fastcgi_params;
    }
}

启动php-fpm 和nginx

systemctl enable php72-php-fpm
systemctl restart php72-php-fpm
systemctl restart nginx

在你的网站目录下丢一个phpinfo.php的文件测试吧

<?php
  // test script for CentOS/RHEL 7+PHP 7.2+Nginx 
  phpinfo();
?>

How to install PHP 7.2 on CentOS 7/RHEL 7
Cento7にphp-fpmをインストールし、nginxと連携する


扫描二维码,在手机上阅读!

添加新评论