【问题标题】:PHP-FPM not running on Nginx under OS X MojavePHP-FPM 未在 OS X Mojave 下的 Nginx 上运行
【发布时间】:2019-07-04 16:08:33
【问题描述】:

我从 Mac 上的 Sierra 升级到 Mojave,升级并安装 php-fpm (php)、nginx 并写入新配置。

PHP 没有解析 php 代码,我可以在标题上看到它正在运行 PHP,甚至日志也显示了它。但是,当它呈现页面时,它是空白的。也没有有用的日志。

curl -v localhost.test/info.php * 尝试 127.0.0.1... * TCP_NODELAY 设置 * 连接到 localhost.test (127.0.0.1) 端口 80 (#0)

GET /info.php HTTP/1.1 主机:localhost.test 用户代理:curl/7.54.0 接受:/

[11-Feb-2019 15:21:30] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[11-Feb-2019 15:21:30] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[11-Feb-2019 15:21:30] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[11-Feb-2019 15:21:30] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[11-Feb-2019 15:21:30] NOTICE: fpm is running, pid 22336
[11-Feb-2019 15:21:30] NOTICE: ready to handle connections

目前获得了以下(全部通过 Homebrew 安装)。

  1. PHP 7.3.1
  2. NGINX 1.15.8

/usr/local/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;

    include servers/*;
}

/usr/local/etc/nginx/servers/localhost.conf

server {
    listen 80;
    server_name localhost.test;
    access_log  /usr/local/var/log/nginx/localhost.test.access.log;

    index index.php;

    root /Users/louie/Development/php;

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
    }
}

这可能是什么原因导致它无法解析 PHP 代码?

【问题讨论】:

标签: php nginx macos-mojave


【解决方案1】:

确保 ~.php 是正确的。

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include        /usr/local/etc/nginx/fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }

也与nginx showing blank PHP pages有关

【讨论】:

    【解决方案2】:

    如果页面为空白,则很可能是 PHP 出错了。用输出当前配置的简单内容替换 PHP 页面:

    <?php phpinfo();
    

    如果可行,您就知道问题出在您的 PHP 上。

    【讨论】:

    • 谢谢。我错过了配置中的包含参数和其余的 fastcgi_param 选项。在我修改它并仔细检查后,重新启动。现在可以了。
    • @LouieMiranda 很高兴它有效!您应该将其发布为您的问题的答案并将其标记为答案,以帮助遇到此问题的其他人。
    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多