搭建LNMP环境(二):安装PHP

admin2022-12-29  111

安装完Tengine之后要安装PHP环境。

 

先安装EPEL库:

yum install -y epel-release

 

安装remi库 CentOS 7 / RHEL 7:

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

 

根据资料显示,remi默认是禁用的,检查REMI是否已经成功安装,使用这个命令:

yum repolist disabled | grep remi

 

安装yum-utils工具包:

yum install -y yum-utils

 

开启remi库:

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

 

查找有没有PHP7.2的软件包:

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

 

有PHP72的包太多了,也不知道行不行,不管了,先安装(php7.2)再说:

yum install -y php72

 

安装php72-php-fpm,和一些其他模块:

yum install -y 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 --version

 

验证安装的模块:

php72 --modules

 

看起来都OK了。

 

设置开机启动 php fpm服务:

systemctl enable php72-php-fpm.service

 

运行 php fpm服务:

systemctl start php72-php-fpm.service

 

查看 php fpm服务状态:

systemctl status php72-php-fpm.service

 

想要关闭php fpm服务就用这个命令:

systemctl stop php72-php-fpm.service

 

需要重启php fpm服务就用这个命令:

systemctl restart php72-php-fpm.service

 

systemctl命令的用法都是一样的。

 

PHP已经安装好了,要配置Tengine,让WEB服务器可以解析PHP。

 

查看服务用户和用户组:

egrep '(user|group)' /opt/nginx/conf/nginx.conf

 

编辑php-fpm.ini配置文件:

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

 

设置用户名和用户组,将配置文件中的user和group两项修改为下面的内容:

user = www
group = www

 

重新启动php-fpm服务:

systemctl restart php72-php-fpm.service

 

修改nginx配置:

vi /opt/nginx/conf/nginx.conf

 

在server段中找到如下内容:

#location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

 

修改成:

location ~ \.php$ {
            root           /opt/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

 

重新启动nginx:

systemctl restart tengine

 

在/opt/nginx/html/下创建foo.php测试文件,并添加一下内容,保存退出:

vi /opt/nginx/html/foo.php

 

增加以下内容:

<?php
phpinfo();
?>

 

相关的一些信息:

# php安装路径
/etc/opt/remi/php72
#nginx配置文件
/opt/nginx/conf/nginx.conf
#nginx默认项目路径
/opt/nginx/html

#创建一个软连接php执行php72
which php72
cd /usr/bin
ln -s php72 php

 

PS:如此安装完成之后,是默认开启了OPcache的,查看phpinfo信息,Zend Memory Manager显示是enabled,开启状态。

 

这样安装的PHP7.2总是有个remi文件夹,而且后面安装yac缓存扩展也并不是很方便,可能还需要研究一下有没有更方便的方法。

转载请注明原文地址:http://www.198484.com/?read-40.html
0

最新回复(0)