php - 在 Ubuntu 中使用 Foreman 在本地运行 Heroku PHP 项目时权限不正确

标签 php ubuntu heroku nginx fastcgi

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

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

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

存在与一些缺少的包和 PHP 版本相关的错误,所以我做了以下操作:

1)。从自定义 PPA (ppa:ondrej/php5) 安装最新的 PHP 版本:
php --versionPHP 5.5.18-1+deb.sury.org~trusty+1 (cli) (built: Oct 17 2014 15:20:47) .

2)。为 php5-fpm 创建了符号链接(symbolic link)二进制:
sudo ln -s /usr/sbin/php5-fpm /usr/local/bin/php-fpm
3)。已安装 nginx .

4)。更改了 文件 :
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 错误网关 错误。

从 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" .

套接字文件归 root 所有并且 nginx 运行为 www-data .

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

最佳答案

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

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

我刚刚修复了错误日志文件的权限(对其进行了修改),然后运行 ​​heroku local像平常一样

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

如果您修复权限然后运行 ​​heroku local (没有 sudo),然后都以无人身份运行,它对我有用。

关于php - 在 Ubuntu 中使用 Foreman 在本地运行 Heroku PHP 项目时权限不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26769361/

相关文章:

php - 获取 MySQL 中 3 个类别的所有可能组合

python - 查找工具/脚本/子目录

python - 守护程序输出未写入 TXT

带有 Express 应用程序的 Node.js 在 Heroku 上崩溃,在本地工作

javascript - Magento 添加到购物车按钮,单页结帐仅在刷新浏览器后才起作用

php - 根据另一个表的列值从一个表中选择一条记录

php - 没有问号的 GET 请求

ubuntu - EC2 Ubuntu : unable to access site from browser but able to access from EC2 ubuntu terminal

java - 使用 Ebean NullPointerException 玩 2.4

php - 无法在 Heroku 上访问 AWS RDS MySQL + PHP