【问题标题】:Incorrect permissions when running Heroku PHP project locally with Foreman in Ubuntu在 Ubuntu 中使用 Foreman 在本地运行 Heroku PHP 项目时权限不正确
【发布时间】:2016-05-20 18:22:07
【问题描述】:

我在 Xubuntu 14.04 机器的本地目录中有一个 Heroku PHP 项目。

我想在本地运行它,以便在部署到 Heroku 之前对其进行开发/测试。

首先,我尝试 cd 进入项目目录并运行foreman start web

有一些缺失的包和 PHP 版本相关的错误,所以我做了以下操作:

1)。从自定义 PPA (ppa:ondrej/php5) 安装最新的 PHP 版本:

php --version

PHP 5.5.18-1+deb.sury.org~trusty+1 (cli) (built: Oct 17 2014 15:20:47).

2)。为php5-fpm 二进制文件创建了符号链接:

sudo ln -s /usr/sbin/php5-fpm /usr/local/bin/php-fpm

3)。已安装 nginx

4)。更改了 Procfile

web: vendor/bin/heroku-php-nginx /web

接下来,我尝试使用:foreman start web 命令启动服务器,我得到以下输出:

02:38:23 web.1  | started with pid 15815
02:38:23 web.1  | Booting on port 5000...
02:38:23 web.1  | DOCUMENT_ROOT changed to '/web/'
02:38:24 web.1  | Starting php-fpm...
02:38:24 web.1  | Starting nginx...
02:38:24 web.1  | [06-Nov-2014 02:38:24] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
02:38:24 web.1  | [06-Nov-2014 02:38:24] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
02:38:26 web.1  | nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
02:38:26 web.1  | 2014/11/06 02:38:26 [warn] 15897#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
02:38:26 web.1  | 2014/11/06 02:38:26 [emerg] 15897#0: open() "/var/log/nginx/access.log" failed (13: Permission denied)
02:38:26 web.1  | Process exited unexpectedly: nginx
02:38:26 web.1  | Going down, terminating child processes...
02:38:26 web.1  | vendor/bin/heroku-php-nginx: line 282: 15891 Terminated              tail -qF -n 0 "${logs[@]}"
02:38:26 web.1  |      15892                       | strip_fpm_child_said 1>&2
02:38:26 web.1  | exited with code 1
02:38:26 system | sending SIGTERM to all processes

显然,它无法启动,因为它无法访问 root 用户拥有的日志文件。

接下来,我尝试使用 sudo:sudo foreman start web 启动它并获得以下输出:

02:43:29 web.1  | started with pid 16153
02:43:30 web.1  | Booting on port 5000...
02:43:30 web.1  | DOCUMENT_ROOT changed to '/web/'
02:43:30 web.1  | Starting php-fpm...
02:43:30 web.1  | Starting nginx...
02:43:32 web.1  | nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
02:43:32 web.1  | nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
02:43:32 web.1  | nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
02:43:32 web.1  | nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
02:43:33 web.1  | nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
02:43:33 web.1  | nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
02:43:33 web.1  | nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
02:43:33 web.1  | nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
02:43:34 web.1  | nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
02:43:34 web.1  | nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
02:43:34 web.1  | nginx: [emerg] still could not bind()
02:43:34 web.1  | Process exited unexpectedly: nginx
02:43:34 web.1  | Going down, terminating child processes...
02:43:34 web.1  | vendor/bin/heroku-php-nginx: line 282: 16229 Terminated              tail -qF -n 0 "${logs[@]}"
02:43:34 web.1  |      16230                       | strip_fpm_child_said 1>&2
02:43:34 web.1  | exited with code 1
02:43:34 system | sending SIGTERM to all processes

看起来它不喜欢那个 nginx 服务正在运行。这是为什么呢?

我正在使用 sudo service nginx stop 关闭网络服务器并重试。

这次没有错误消息,看起来服务器正在运行。

但是,当我在浏览器中加载网页时,我收到了 HTTP 的 502 Bad Gateway 错误。

从 nginx 错误日志我可以看到 nginx 无法访问 FastCGI 套接字文件:

2014/11/06 02:45:44 [crit] 16342#0: *1 connect() to unix:/tmp/heroku.fcgi.5000.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/heroku.fcgi.5000.sock:", host: "localhost:5000".

socket 文件归root 所有,nginx 以www-data 运行。

这是什么原因,我该如何解决这个问题?是否可以从我的用户(不是 root)本地运行 Heroku?

【问题讨论】:

    标签: php ubuntu heroku nginx fastcgi


    【解决方案1】:

    我也遇到过同样的问题(在 Mac OS 上,使用自制软件全新安装 nginx)。

    我没有编辑vendor/heroku/heroku-buildpack-php/conf/nginx/heroku.conf.php(它会在 buildback 更新时被覆盖,无论如何现在它略有不同)。

    我刚刚修复了错误日志文件的权限(对其进行了chmod),然后正常运行heroku local

    如果您以 root 身份运行 heroku local,这将解决您的错误日志权限错误,但随后 nginx 以 root 身份运行而 php-fpm 以无人身份运行(在我的情况下),因此上述权限不匹配。

    如果你修复了权限,然后运行heroku local(没有 sudo),那么两者都以无人身份运行,它对我有用。

    【讨论】:

    【解决方案2】:

    你的情况和我一模一样。

    问题是nginx和php5-fpm的进程权限不同。 快速修复:

    第一:

    编辑文件:vendor/heroku/heroku-buildpack-php/conf/nginx/heroku.conf.php

    评论:#server unix:/tmp/heroku.fcgi..sock max_fails=3 fail_timeout=3s;

    打开注释并更改端口:服务器 127.0.0.1:9000 max_fails=3 fail_timeout=3s;

    第二:

    编辑文件:vendor/heroku/heroku-buildpack-php/conf/php/php-fpm.conf

    评论:听 = /tmp/heroku.fcgi.${PORT}.sock

    打开评论并更改端口:listen = 127.0.0.1:9000

    【讨论】:

      猜你喜欢
      • 2014-12-23
      • 2020-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多