在Heroku上部署PHP项目

时间:2015-03-15 12:14:22

标签: php heroku

我已经在heroku上成功部署了我的PHP项目,但问题是每当我输入" Heroku Open"要加载网页网址,我收到以下错误:

 Forbidden
 You don't have permission to access / on this server.

我知道问题可能来自服务器配置,我的ht-access,甚至Apache配置,并且我尝试过各种更改,但是到目前为止它们都没有工作,这里是heroku日志:

015-03-15T10:47:30.266691+00:00 heroku[api]: Release v2 created by pouya.ataei.7@gmail.com
2015-03-15T10:50:02.189549+00:00 heroku[api]: Scale to web=1 by pouya.ataei.7@gmail.com
2015-03-15T10:50:02.262334+00:00 heroku[api]: Deploy d388ddf by  pouya.ataei.7@gmail.com
2015-03-15T10:50:02.262334+00:00 heroku[api]: Release v3 created by pouya.ataei.7@gmail.com
2015-03-15T10:50:08.597918+00:00 heroku[web.1]: Starting process with command `vendor/bin/heroku-php-apache2`
2015-03-15T10:50:10.812072+00:00 app[web.1]: Starting php-fpm...
2015-03-15T10:50:10.620318+00:00 app[web.1]: Optimzing defaults for 1X dyno...
2015-03-15T10:50:10.802110+00:00 app[web.1]: 4 processes at 128MB memory limit.
2015-03-15T10:50:12.815707+00:00 app[web.1]: Starting httpd...
2015-03-15T10:50:13.132692+00:00 heroku[web.1]: State changed from starting to up
2015-03-15T10:50:38.639895+00:00 heroku[api]: Scale to web=1 by pouya.ataei.7@gmail.com
2015-03-15T10:50:49.465371+00:00 heroku[router]: at=info method=GET path="/" host=boiling-bastion-7861.herokuapp.com request_id=92b6872e-c060-4e06-8ede-5d44ea335ada fwd="175.140.77.229" dyno=web.1 connect=1ms service=3ms status=403 bytes=387
2015-03-15T10:50:49.465802+00:00 app[web.1]: 10.123.194.135 - - [15/Mar/2015:10:50:49 +0000] "GET / HTTP/1.1" 403 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
2015-03-15T10:50:49.465396+00:00 app[web.1]: [Sun Mar 15 10:50:49.463558 2015] [autoindex:error] [pid 117:tid 140423049713408] [client 10.123.194.135:31742] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (home.php) found, and server-generated directory index forbidden by Options directive
2015-03-15T10:50:49.907445+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=boiling-bastion-7861.herokuapp.com request_id=76865ea0-628f-426f-8bad-5507aa052fb4 fwd="175.140.77.229" dyno=web.1 connect=1ms service=5ms status=200 bytes=3964
2015-03-15T10:50:49.906266+00:00 app[web.1]: 10.123.194.135 - - [15/Mar/2015:10:50:49 +0000] "GET /favicon.ico HTTP/1.1" 200 3754 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
2015-03-15T10:53:30.128901+00:00 heroku[router]: at=info method=GET path="/" host=boiling-bastion-7861.herokuapp.com request_id=56038276-5eb7-40ad-8615-cc695a72cdcb fwd="175.140.77.229" dyno=web.1 connect=1ms service=2ms status=403 bytes=387
2015-03-15T10:53:30.129676+00:00 app[web.1]: 10.91.13.225 - - [15/Mar/2015:10:53:30 +0000] "GET / HTTP/1.1" 403 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
2015-03-15T10:53:30.129331+00:00 app[web.1]: [Sun Mar 15 10:53:30.128673 2015] [autoindex:error] [pid 102:tid 140423284651776] [client 10.91.13.225:15561] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (home.php) found, and server-generated directory index forbidden by Options directive
2015-03-15T10:53:30.686329+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=boiling-bastion-7861.herokuapp.com request_id=9bfc7392-7f31-49ff-831a-55dbd0812914 fwd="175.140.77.229" dyno=web.1 connect=3ms service=4ms status=200 bytes=3964
2015-03-15T10:53:30.686175+00:00 app[web.1]: 10.91.13.225 - - [15/Mar/2015:10:53:30 +0000] "GET /favicon.ico HTTP/1.1" 200 3754 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
2015-03-15T11:06:22.231815+00:00 heroku[router]: at=info method=GET path="/" host=boiling-bastion-7861.herokuapp.com request_id=3a2df217-758f-469c-884a-3f27072dda7d fwd="175.140.77.229" dyno=web.1 connect=4ms service=7ms status=403 bytes=387
2015-03-15T11:06:22.228756+00:00 app[web.1]: 10.93.25.70 - - [15/Mar/2015:11:06:22 +0000] "GET / HTTP/1.1" 403 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
2015-03-15T11:06:22.228440+00:00 app[web.1]: [Sun Mar 15 11:06:22.227460 2015] [autoindex:error] [pid 104:tid 140423183963904] [client 10.93.25.70:29123] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (home.php) found, and server-generated directory index forbidden by Options directive
2015-03-15T11:06:22.710597+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=boiling-bastion-7861.herokuapp.com request_id=ad006b2f-00fe-426e-81f0-e2a8d8e9e457 fwd="175.140.77.229" dyno=web.1 connect=1ms service=10ms status=200 bytes=3964
2015-03-15T11:06:22.709151+00:00 app[web.1]: 10.93.25.70 - -   [15/Mar/2015:11:06:22 +0000] "GET /favicon.ico HTTP/1.1" 200 3754 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36

可能的解决方案是什么?!任何考虑都表示赞赏......

1 个答案:

答案 0 :(得分:7)

Apache在你的错误日志中告诉你这里的问题是什么(为了便于阅读,我把它包起来):

2015-03-15T10:50:49.465396+00:00 app[web.1]: [Sun Mar 15 10:50:49.463558 2015]
  [autoindex:error] [pid 117:tid 140423049713408] [client 10.123.194.135:31742]
  AH01276: Cannot serve directory /app/: No matching DirectoryIndex (home.php) found,
  and server-generated directory index forbidden by Options directive

您显然在DirectoryIndex home.php文件中的.htaccess位置,但没有home.php,所以当您尝试转到/时,它找不到文件(当你只请求目录本身时会使用它,/),并且在默认配置中不允许列出目录内容(这不是你想要的)。

因此,您需要使用代码创建home.php,更改.htaccess以删除DirectoryIndex语句,以便index.php / index.html(如果如果您的home.php和其他所有内容不在项目的根目录中,而是在publicwebdefine a document root using the documented argument in your Procfile command这样的子目录中:

web: vendor/bin/heroku-php-apache2 public/