【发布时间】: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