• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Mark的小试牛刀

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

Linux下安装PHP环境并配置Nginx支持php-fpm模块

修改php配置

vi /etc/php.ini
打开php配置文件/etc/php.ini找到cgi.fix_pathinfo配置项,这一项默认被注释并且值为1,根据官方文档的说明,这里为了当文件不存在时,阻止Nginx将请求发送到后端的PHP-FPM模块,从而避免恶意脚本注入的攻击,所以此项应该去掉注释并设置为0
重启php

kill php进程ID

/usr/sbin/php-fpm

修改nginx配置


vi `/etc/nginx/conf.d/default.conf`

修改文件为:

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        include /etc/nginx/default.d/*.conf;

        location / {
            root   /usr/share/nginx/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 404 /404.html;
                location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
                location = /50x.html {
        }
}

重启nginx
kill nginx进程ID

/usr/sbin/nginx

测试php能不能用

cd /usr/share/nginx/html

touch a.php
写以下内容
<?php
echo 12345;

posted on 2018-03-19 11:32  我是天才啊  阅读(179)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3