【问题标题】:Zend Framework Hosting - cannot include bootstrap.phpZend 框架托管 - 不能包含 bootstrap.php
【发布时间】:2014-11-15 18:36:11
【问题描述】:

我正在为我的 Zend Framework 应用程序使用托管解决方案,但无法让它加载 application/bootstrap.php 文件。

当我通过 ftp 访问服务器时,我的文档根目录是 /webspace/httpdocs/euro.millionsresults.com

我将应用程序、公共、库等目录放在此目录中。

然后我根据http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/创建了一个.htaccess

/webspace/httpdocs/euro.millionsresults.com/.htaccess

RewriteEngine On
RewriteRule .* index.php

这会将所有内容重写到我的 index.php 文件中,然后该文件包含 ZF 的 public/index.php 文件,这是正确的并且可以正常工作。 index.php 文件为:

/webspace/httpdocs/euro.millionsresults.com/index.php

<?php
include 'public/index.php';

如果我在 public/index.php 文件中添加一个回显,它可以正常工作,证明当您尝试访问该站点时现在调用了 public/index.php。

问题是,public/index.php 文件需要包含 ../application/bootstrap.php 文件:

/webspace/httpdocs/euro.millionsresults.com/public/index.php

<?php
echo "this is working";
require('../application/bootstrap.php');

但是,application/bootstrap.php 不包含在内。

如果我在 application/bootstrap.php 的最顶部放置一个骰子,则不会渲染任何内容。

我已经为 public/index.php 尝试了以下内容:

require('../../../application/bootstrap.php'); 要求('/webspace/httpdocs/euro.millionsresults.com/application/bootstrap.php');

但是在包含 application/bootstrap.php 时没有任何作用。

有人知道在这里做什么吗?这是我使用的廉价主机,无法访问 php.ini。

其他信息

问题似乎出在 include_path 上。当我执行 get_include_path() 时,我有:

:/php/includes:/usr/share/pear:/usr/libexec/php4-cgi/share/pear:/opt/alt/php55/usr/share/pear:/opt/alt/php54/usr/share/pear:/opt/alt/php53/usr/share/pear

我可以设置_include_path(),但是我要设置什么?

我试过了:

set_include_path('/webspace/httpdocs/euro.millionsresults.com/application' . PATH_SEPARATOR. get_include_path());
set_include_path('/../../../application' . PATH_SEPARATOR . get_include_path());
set_include_path('../application' . PATH_SEPARATOR . get_include_path());

这些都不起作用,即当我的 public/index.php 文件中有以下内容时,我总是得到“不存在”:

<?php
echo "In file public/index.php <br>";

set_include_path('/../../../application' . PATH_SEPARATOR . get_include_path());

echo get_include_path();

if (file_exists('/../application/bootstrap.php')){
    echo "<br>exists";
}
else {
    echo "<br>does not exist";
}

我检查存在的文件无关紧要 - 找不到应用程序文件夹中的任何文件,或任何不公开的文件夹。

【问题讨论】:

  • 这个文件夹的权限是什么?它的所有者是哪个用户/组?
  • 我的 zend 框架 .htaccess 文件是: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
  • 我的 Zend .htaccess 文件也不一样,我上面贴的 .htaccess 只是将所有内容重定向到 doc 根目录下的 index.php,然后调用 ZF public/index.php 文件。
  • 权限为 755,所有者与所有其他目录的所有者相同。
  • 我认为 .htaccess 文件是导致此问题的原因。还需要使用 realpath(dirname(FILE) . '/../application'))

标签: php zend-framework


【解决方案1】:

在您的public/index.php 文件中,这一行:

require('../application/bootstrap.php');

假设您的当前工作目录public/,并且相对于这个目录,向上一个目录,有一个application/bootstrap.php - 相对require调用相对于当前工作目录或 include_path。 ZF 代码似乎假定 public/ 是文档根目录,但在您的情况下并非如此。

在 Web 环境中,当前工作目录通常是文档根目录。因此,在您的情况下,您可能希望将 require('../application/bootstrap.php') 更改为:

require('application/bootstrap.php');

如果这不起作用,我建议通过运行以下命令找出当前工作目录与public/index.php 目录的对比:

var_dump(getcwd(), __DIR__);

(如果您的 PHP 版本过时,请将__DIR__ 替换为dirname(__FILE__)

并且,做你的require 电话相对于那个。

【讨论】:

  • 啊,就是这样!谢谢
猜你喜欢
  • 2011-09-14
  • 2012-06-05
  • 2011-03-28
  • 1970-01-01
  • 1970-01-01
  • 2012-09-08
  • 2012-04-22
  • 2012-06-14
  • 2012-10-24
相关资源
最近更新 更多