分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

nginx php-fpm

发布时间:2023-09-06 01:32责任编辑:顾先生关键词:nginx

安装Nginx

[root@node1 ~]# yum install -y nginx 

安装PHP

检查当前安装的PHP包

[root@node1 ~]# yum list installed | grep php 

如果有安装的PHP包,先删除他们

[root@node1 ~]# yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64 ?

配置yum源

[root@node1 ~]# yum install epel-release[root@node1 ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

安装PHP5.6.x

[root@node1 ~]# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

查看版本

[root@node1 ~]# php --version

安装PHP-fpm

[root@node1 ~]# yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm ?

配置与优化PHP-FPM

[root@node2 ~]# vim /etc/php-fpm.d/www.conf

完成php-fpm后,对其运行用户进行配置

[root@node1 ~]# vim etc/php-fpm.conf 修改:user = nginxgroup = nginx如果nginx用户不存在,那么先添加nginx用户[root@node1 ~]# groupadd nginx[root@node1 ~]# useradd -g nginx nginx

修改nginx配置文件以支持php-fpm

[root@node1 ~]# vim /etc/nginx/nginx.conf

加入蓝色字体

worker_processes ?1;events { ???worker_connections ?1024;}http { ???include ??????mime.types; ???default_type ?application/octet-stream; ???sendfile ???????on; ???keepalive_timeout ?65; ???server { ???????listen ??????80; ???????server_name ?localhost; ???????location / { ???????????root ??html; ???????????index ?index.html index.htm; ???????location ~ \.php$ { ???????????root html; ???????????fastcgi_pass 127.0.0.1:9000; ???????????????fastcgi_index index.php; ???????????fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ???????????include fastcgi_params;} ???????} ???????error_page ??500 502 503 504 ?/50x.html; ???????location = /50x.html { ???????????root ??html; ???????} ???}}

通过location指令,将所有以php为后缀的文件都交给127.0.0.1:9000来处理,而这里的IP地址和端口就是FastCGI进程监听的IP地址和端口。
fastcgi_param指令指定放置PHP动态程序的主目录,也就是$fastcgi_script_name前面指定的路径,这里是/usr/local/nginx/html目录,建议将这个目录与Nginx虚拟主机指定的根目录保持一致,当然也可以不一致。
fastcgi_params文件是FastCGI进程的一个参数配置文件,在安装Nginx后,会默认生成一个这样的文件,这里通过include指令将FastCGI参数配置文件包含了进来

在 /usr/share/nginx/html/下创建index.php文件

[root@node1 ~]# vim /usr/share/nginx/html/index.php插入以下内容<?php ???echo phpinfo();?>

启动php-fpm和nginx

[root@node1 ~]# systemctl start php-fpm
[root@node1 ~]# systemctl start nginx

查看进程数

[root@node1 ~]# ps aux | grep -c php-fpm

查看监听的IP地址和端口相关信息

[root@node1 ~]# netstat -antl|grep 9000
[root@node1 ~]# ps -ef|grep php-cgi ?

 访问http://ip地址/index.php,皆可以见到php信息了

参考文档:

http://www.linuxidc.com/Linux/2010-05/26149.htmhttp://www.nginx.cn/231.htmlhttps://www.cnblogs.com/mangguoxiansheng/p/5967745.htmlhttps://www.cnblogs.com/txtfashion/p/3669524.htmlhttp://blog.51cto.com/ixdba/806622http://www.thinkphp.cn/topic/48196.html


 

 

 

 

 

nginx php-fpm

原文地址:https://www.cnblogs.com/wanglan/p/8124877.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved