【问题标题】:CakePHP shows blank page with no errors at remote serverCakePHP 在远程服务器上显示没有错误的空白页面
【发布时间】:2016-04-25 00:32:55
【问题描述】:

我有一个 CakePHP 2.5.1 站点托管在 CentOS 专用服务器上,该服务器安装了 CPanel(包括 apache、exim、php 等),在这个站点上我有一个管理区域,但由于某种原因,只有这个区域在本地主机上正常工作,如果我将站点上传到远程服务器,它只会显示一个空白页面。

Obs:站点的所有其余部分都正常工作,只有管理区域不工作。

Obs²:有一天我将网站上传到另一台服务器并且该区域正在工作,所以我认为问题可能出在服务器上。

我向 CPanel 寻求技术支持,但只要他们不知道 CakePHP 的工作原理,他们就无法帮助我,但他们尝试了。

我知道不建议使用外部链接,顺便说一句,我确定我确实无法在其他地方重现该问题,因此有指向空白页面的链接:http://www.acheiapartamento.com.br/biz/

这里是定义的routes.php(你可以看到“/biz/”url指向页面控制器索引):

<?php

/**
 * Routes configuration
 *
 * In this file, you set up routes to your controllers and their actions.
 * Routes are very important mechanism that allows you to freely connect
 * different URLs to chosen controllers and their actions (functions).
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Config
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/View/Pages/home.ctp)...
 */
/* BIZ */
Router::connect('/biz/', array('controller' => 'pages', 'action' => 'index', 'biz' => 'true'));


/* HOME */
Router::connect('/', array('controller' => 'home', 'action' => 'index'));
Router::connect('/home', array('controller' => 'home', 'action' => 'index'));

Router::connect('/classificados-home', array('controller' => 'home', 'action' => 'classificados'));
Router::connect('/destaques-home', array('controller' => 'home', 'action' => 'destaques'));
Router::connect('/lancamentos-home', array('controller' => 'home', 'action' => 'lancamentos'));


/* EMPRESA */
Router::connect('/sobre', array('controller' => 'institucionais', 'action' => 'index'));
Router::connect('/dicas', array('controller' => 'institucionais', 'action' => 'dicas'));

/* EMPREENDIMENTOS */
Router::connect('/destaques', array('controller' => 'empreendimentos', 'action' => 'index'));
Router::connect('/empreendimentos/enviar_contato', array('controller' => 'empreendimentos', 'action' => 'enviar_contato'));
Router::connect('/destaques/:slug', array('controller' => 'empreendimentos', 'action' => 'interna'));
Router::connect('/empreendimentos/:slug', array('controller' => 'empreendimentos', 'action' => 'interna'));
Router::connect('/buscador', array('controller' => 'empreendimentos', 'action' => 'busca'));
Router::connect('/resultado', array('controller' => 'empreendimentos', 'action' => 'resultado'));
Router::connect('/classificados', array('controller' => 'empreendimentos', 'action' => 'classificados'));
//Router::connect('/lancamentos', array('controller' => 'empreendimentos', 'action' => 'lancamentos'));
Router::connect('/lancamentos/enviar_contato', array('controller' => 'lancamentos', 'action' => 'enviar_contato'));
Router::connect('/lancamentos', array('controller' => 'lancamentos', 'action' => 'index'));
Router::connect('/lancamentos/:slug', array('controller' => 'lancamentos', 'action' => 'interna'));


/*EMPREENDIMENTOS BAIRROS*/
Router::connect('/bairros/busca', array('controller' => 'empreendimentos_bairros', 'action' => 'busca'));

/*CLIENTE */ 
Router::connect('/blog', array('controller' => 'noticias', 'action' => 'index'));
Router::connect('/blog/:slug', array('controller' => 'noticias', 'action' => 'interna'));
Router::connect('/ache-para-mim', array('controller' => 'interesse', 'action' => 'index'));
Router::connect('/ache-para-mim/comercial', array('controller' => 'interesse', 'action' => 'comercial'));

Router::connect('/atendimentos', array('controller' => 'atendimentos', 'action' => 'index'));
Router::connect('/clientes', array('controller' => 'clientes', 'action' => 'index'));

Router::connect('/meus-favoritos', array('controller' => 'clientes', 'action' => 'index'));
Router::connect('/meus-imoveis', array('controller' => 'clientes', 'action' => 'meus_imoveis'));


Router::connect('/cadastre-seu-imovel', array('controller' => 'empreendimentos', 'action' => 'cliente_imovel'));

Router::connect('/faq', array('controller' => 'faqs', 'action' => 'index'));

Router::connect('/pergunte-ao-corretor', array('controller' => 'perguntas', 'action' => 'index'));

/* CONTATO */
Router::connect('/contato', array('controller' => 'contatos', 'action' => 'index'));

Router::connect('/aplicativo', array('controller' => 'aplicativos', 'action' => 'index'));


Router::connect('/cortarimagem', array('controller' => 'empreendimentos', 'action' => 'cortarimagem'));

/** EXPORTAÇÃO **/


/* IMPORTACAO */
Router::connect('/importacao/', array('controller' => 'empreendimentos', 'action' => 'importacao'));
Router::connect('/importacao-imagem/', array('controller' => 'empreendimentos', 'action' => 'importacao2'));

/* BEMORAR */
//Router::connect('/exp-bemorar/:id', array('controller' => 'bemorar', 'action' => 'index'));



/**
 * Load all plugin routes. See the CakePlugin documentation on
 * how to customize the loading of plugin routes.
 */
CakePlugin::routes();

/**
 * Load the CakePHP default routes. Only remove this if you do not want to use
 * the built-in default routes.
 */
require CAKE . 'Config' . DS . 'routes.php';

这里是PagesController.php的代码:

<?php

/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
App::uses('AppController', 'Controller');
App::uses('UsersController', 'Controller');
App::uses('BannersController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class PagesController extends AppController {

    /**
     * This controller does not use a model
     *
     * @var array
     */
    public $uses = array();

    /**
     * Displays a view
     *
     * @param mixed What page to display
     * @return void
     * @throws NotFoundException When the view file could not be found
     *  or MissingViewException in debug mode.
     */
    public function display() {

    $path = func_get_args();

        $count = count($path);
        if (!$count) {
            return $this->redirect('/');
        }
        $page = $subpage = $title_for_layout = null;

        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $title_for_layout = Inflector::humanize($path[$count - 1]);
        }
        $this->set(compact('page', 'subpage', 'title_for_layout'));

        try {
            $this->render(implode('/', $path));
        } catch (MissingViewException $e) {
            if (Configure::read('debug')) {
                throw $e;
            }
            throw new NotFoundException();
        }

    }

    public function biz_index() {
        echo "teste";
    }

    public function index() {
        echo "teste";
        $produto = new ProdutosController();
        $this->set('produtos', $produto->Produto->find('all'));
    }

}

同样的代码在 localhost 上工作,localhost 的 phpinfo() 和我的远程服务器几乎是一样的,我已经检查过了。

远程 phpinfo()(不起作用): https://drive.google.com/a/unesc.net/file/d/0Byyr3Jl114rReUg2cnhTSTZ2b1E/view

本地主机 phpinfo()(有效): https://drive.google.com/a/unesc.net/file/d/0Byyr3Jl114rRSTVobzRic2NlWFk/view?usp=sharing

日志上没有出现错误,页面是空白的,所以我真的不知道该怎么做,我需要尽快修复它。

【问题讨论】:

  • 启用调试。在您的app/Config/core.php 文件集中Configure::write('debug', 2);
  • 已经设置为 2。
  • 从 tmp\cache 清除缓存 > 模型、持久性和视图文件夹
  • 我建议您摆脱前缀路由(这不是预期用途)并正确设置 CakePHP 以便它可以从子文件夹运行。请参阅this question 了解更多信息。
  • 有什么证据可以这么说?我在互联网上学到的关于 cakephp 的所有内容都在使用路由,我一生中从未见过 cakephp 不使用这条路由:p 顺便说一句,我试了一下,遇到了很多 500 个内部服务器错误......

标签: php cakephp centos cpanel


【解决方案1】:

我认为您面临的问题是因为权限。以下链接可能对您有所帮助: http://book.cakephp.org/2.0/en/installation.html#permissions

【讨论】:

  • 将所有文件夹权限从 0755 更改为 0777,现在在站点的所有页面中,我得到的不是空白页面,而是 500 内部服务器错误
  • 它的“app”文件夹不能是 0777,否则我得到内部服务器错误
  • 您不应更改所有文件夹权限。您只需要按照文档中给出的说明进行操作。到目前为止,请检查 apache 错误日志是否有任何错误。
  • 还启用调试到您的应用程序。在您的 app/Config/core.php 文件中设置 Configure::write('debug', 2);
  • is 已经启用,当我在目录 public_html 上时,我确实在连接到服务器的 SSH shell 上运行了三个命令,并且没有任何改变。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 2018-11-16
  • 1970-01-01
相关资源
最近更新 更多