【问题标题】:How to set up PHP 7 with NGINX如何使用 NGINX 设置 PHP 7
【发布时间】:2016-03-12 06:36:58
【问题描述】:

我在我的开发 Debian Stable 上安装了 PHP 7 Nightly 和 Nginx 1.9.7(主线):

$ curl http://nginx.org/keys/nginx_signing.key | apt-key add -
$ echo -e 'deb http://nginx.org/packages/mainline/debian/ jessie nginx\ndeb-src http://nginx.org/packages/mainline/debian/ jessie nginx' > /etc/apt/sources.list.d/nginx.list
$ echo -e 'deb http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/' > /etc/apt/sources.list.d/php.list
$ apt-get -y update && time apt-get -y dist-upgrade
$ apt-get -y --force-yes install --fix-missing nginx php7-nightly
$ service nginx restart

我在/etc/nginx/conf.d/php.conf 中有这个配置文件(default.conf 未注释)。这是原始的 default.conf,我只是取消了 PHP fastCGI 行的注释:

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;
        #access_log  /var/log/nginx/log/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        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;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

我还没有在网上找到任何关于如何使用 PHP 7 设置 Nginx Mainline 的教程。 :(

谢谢!

【问题讨论】:

  • 如果使用PHP-FPM SAPI(FastCGI Process Manager),nginx的配置和之前完全一样。使用 FPM SAPI 通常是一个不错的选择,因为它允许您独立于 Web 服务器控制 php 进程(而不是让 nginx 管理 fastcgi 进程),并且不必在每次请求时从头开始重新加载 php 环境(相对于使用常规 CGI)。
  • 你知道如何安装php-fpm到php7的教程吗?有没有办法用包管理器安装它?
  • 从 php 5.3.3 看起来它包含在核心 php 包中。

标签: php nginx fastcgi


【解决方案1】:

在快速浏览一下 zend 提供的软件包(您正在安装的软件包)之后,您必须为您的 init 系统 (systemd) 编写一个脚本来启动和管理 php-fpm 进程。

二进制文件安装在/usr/local/php7/sbin/php-fpm 中。您还必须修改/usr/local/php7/etc 中的配置文件。主要的变化是确保 fpm 在端口 9000 的地址 127.0.0.1 上有一个监听池。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-17
  • 1970-01-01
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
  • 1970-01-01
  • 2012-07-20
相关资源
最近更新 更多