【问题标题】:white screen shows up for php files in ubuntu 16, php 7, using nginx [closed]使用 nginx 在 ubuntu 16、php 7 中显示 php 文件的白屏 [关闭]
【发布时间】:2017-05-10 02:02:10
【问题描述】:

我正在尝试让 php 文件在我的服务器上运行。它有 Ubuntu 16.04.1 LTS (Xenial) 和 PHP 7.0.14-2+deb.sury.org~xenial+1。我一直在努力让这个工作,并在互联网上寻找迄今为止还没有奏效的解决方案。这是我的 /etc/nginx/sites-available/default 文件:

server {
    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;
    listen 443 ssl;
    server_name myurl.com www.myurl.com

    ssl_certificate /some_file_path/...;
    ssl_certificate_key /some_file_path/...;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /some_file_path/...;

    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_stapling on;
    ssl_stapling_verify on;
    add_header Strict-Transport-Security max-age=15768000;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

    location ~ /.well-known {
        allow all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    #       include snippets/fastcgi-php.conf;
    #
    #       # With php7.0-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    #       # With php7.0-fpm:
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #       deny all;
    #}
}

server {
    listen 80;
    server_name myurl.com www.myurl.com;
    return 301 https://$host$request_uri;
}

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }

我在想这个文件可能有问题。 php7.0-fpm 确实存在于/var/run/php/ 中,但它也存在于/run/php 中,我尝试了/var/run/php/php7.0-fpm.sock 和/run/php /php7.0-fpm.sock 在上面写着fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 的行上,但这也不起作用。我在每次更改后运行nginx -t,然后运行sudo service nginx restart,看看它是否有效,但它没有。

普通的 html 文件可以工作,但 php 文件不能工作。我确实尝试了一段时间来安装 php5 以查看我是否可以让它工作而不是 php7(它默认安装,因为我使用的是 ubuntu 16),但是当我这样做时似乎知道 php5-fpm.sock 文件(当我尝试这样做时,我注意到,

`ls /etc/php/5.6` showed `apache2    cli    mods-available`

但没有fpm 目录

作为 ls /etc/php/7.0 显示apache2 cli fpm mods-avaiable

现在,我实际上更愿意让 php 7 工作,但 php 5 将是最后的手段,但正如我上面所展示的,我在让 php5 工作方面处于死胡同,因为没有 php5-fpm。 sock 文件指向 nginx 配置文件,而且似乎 php5-fpm 似乎无论如何都丢失了。我认为这是因为我发现如何在 ubuntu 16 上安装 php5 的说明是针对 apache(但我不确定),并让我为此添加了一个存储库。但我正在使用 nginx。我所说的存储库是:ppa:ondrej/php。如果我无法让 php7 工作,是否有 php5-fpm 的存储库与 nginx 而不是 apache?

注意:我刚刚尝试安装 php7.1-fpm 并更新了配置文件并重新启动了 nginx,但我仍然在 php 页面上出现白屏。

对此的任何帮助将不胜感激。

非常感谢。

【问题讨论】:

  • Server Fault 是新的吗?,因为我为什么在 stackoverflow 上看到大量关于 nginx 配置的问题,而且它们从来没有因为离题而关闭?这确实涉及编程工具,因为我是试图让 PHP 工作,我是一名程序员,而不是网络管理员,但有时我仍然需要做一些事情,比如将 nginx 配置为我的编程的一部分,就像许多其他人一样。

标签: php ubuntu nginx ubuntu-16.04 php-7


【解决方案1】:

我找到了答案。我必须将这一行:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 添加到我的location php block

但在location php block 中使用include fastcgi.conf; 是更持久的解决方案。

我将为遇到此问题的其他人参考此链接: https://www.digitalocean.com/community/questions/website-displaying-blank-page-after-upgrading-ubuntu-server

ubuntu 16 出现这个 nginx php 7 问题的原因是根据 ryanmortier “在更新之前,/etc/nginx/fastcgi_params 有一个 SCRIPT_FILENAME 参数。

但是,更新删除了该行并杀死了许多 php-fpm 站点。”(此引用摘自此答案中发布的链接)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-18
    • 1970-01-01
    • 2013-03-03
    • 2016-12-28
    • 1970-01-01
    • 2016-08-10
    • 2015-10-03
    相关资源
    最近更新 更多