【问题标题】:PHP Fatal error: Uncaught Error: Class 'cake\\lib\\Dispatcher' not foundPHP 致命错误:未捕获的错误:找不到类 'cake\\lib\\Dispatcher'
【发布时间】:2020-04-12 16:35:25
【问题描述】:

我在 Ubuntu 18.04 LTS 上运行 Apache 2.4.29 和 php 7.2。我的数据文件 (/var/www/cake/prod/webroot/) 是从 Apache 2.2.20 迁移而来的,php 5 在 Ubuntu 11.10 上运行。

我的 apache 服务运行正常,但是当我尝试访问该网站 (https://my_ip:8080/users/login) 时,它显示: my_ip 当前无法处理此请求。

我检查 Apache 错误日志并显示以下错误消息:

[Fri Dec 20 05:52:47.177805 2019] [php7:error] [pid 10916] [client ip:19466] PHP 致命错误:未捕获的错误:在 /var/www/cake/ 中找不到类“调度程序” prod/webroot/index.php:82\n堆栈跟踪:\n#0 {main}\n 在第 82 行的 /var/www/cake/prod/webroot/index.php 中抛出

/var/www/cake/prod/webroot/index.php 的内容

<?php
/**
 * Index
 *
 * The Front Controller for handling every request
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app.webroot
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
/**
 * Use the DS to separate the directories in other defines
 */
if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}
/**
 * These defines should only be edited if you have cake installed in
 * a directory layout other than the way it is distributed.
 * When using custom settings be sure to use the DS and do not add a trailing DS.
 */

/**
 * The full path to the directory which holds "app", WITHOUT a trailing DS.
 *
 */
if (!defined('ROOT')) {
    define('ROOT', dirname(dirname(dirname(__FILE__))));
}
/**
 * The actual directory name for the "app".
 *
 */
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}
/**
 * The absolute path to the "cake" directory, WITHOUT a trailing DS.
 *
 */
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    define('CAKE_CORE_INCLUDE_PATH', ROOT);
}

/**
 * Editing below this line should NOT be necessary.
 * Change at your own risk.

*/
if (!defined('WEBROOT_DIR')) {
    define('WEBROOT_DIR', basename(dirname(__FILE__)));
}
if (!defined('WWW_ROOT')) {
    define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
    if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
      define('APP_PATH', null);
      define('CORE_PATH', null);
    } else {
        define('APP_PATH', ROOT . DS . APP_DIR . DS);
        define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
    }
}
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'prod' . DS . 'config' . DS . 'bootstrap.php')) {
    trigger_error("CakePHP core could not be found.  Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php.  It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vend$
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
    return;
} else {
    $Dispatcher = new Dispatcher();
    $Dispatcher->dispatch();
}

/etc/apache2/sites-enabled/000-default.conf 的内容

<VirtualHost *:8080>
    ServerAdmin webmaster@localhost

    SSLEngine on
    <FilesMatch ".(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
    SSLOptions +StdEnvVars
    </Directory>

    DocumentRoot /var/www/cake/prod/webroot

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/cake/prod/webroot>
        SSLRequireSSL
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

    SSLVerifyClient none
    SSLProxyEngine off

    Include /var/www/foswiki/foswiki_httpd_conf.txt
    <IfModule mime.c>
    AddType application/x-x509-ca-cert      .crt
    AddType application/x-pkcs7-crl         .crl
    </IfModule>

</VirtualHost>

【问题讨论】:

  • 您是否从另一台正在运行的服务器上复制了该站点?如果是这样,您是从/var/www/cake 复制所有内容,还是仅复制/var/www/cake/prod/webroot
  • 另外,这到底是在运行什么版本的 CakePHP?
  • Apache 配置与您的问题无关。这看起来像是一个旧版本的 CakePHP,它似乎与 the last release of the 1.x branch 匹配。 include_path 设置为什么,该路径中是否存在文件?
  • 实际上,基于错误ini_set 已禁用,您需要明确包含Dispatcher 类like so
  • 我已经复制了 /var/www/cake 中的所有文件。

标签: php apache cakephp ubuntu-18.04 dispatcher


【解决方案1】:

根据index.php 文件,此版本的CakePHP 与PHP 版本4 和5 兼容,并且您在服务器上安装了PHP 7.2。

您应该将 CakePHP 更新到与 PHP 7.2 兼容的最新可用版本。

【讨论】:

  • 确实这是下一个要面对的问题 (ref),但这并不能回答(暗示的)为什么第一次尝试加载类失败的问题。
  • cakephp版本为4.0.0
  • 我包含了require LIBS . 'dispatcher.php';这一行,错误信息是:[] [php7:warn] [pid 26159] [client :23707] PHP Warning: Use of undefined constant LIBS - assumed 'LIBS' (this will throw an Error in a future version of PHP) in /var/www/cake/prod/webroot/index.php on line 82 [] [php7:warn] [pid 26159] [client :23707] PHP Warning: require(LIBSdispatcher.php): failed to open stream: No such file or directory in /var/www/cake/prod/webroot/index.php on line 82
  • 还有以下内容:[] [php7:error] [pid 26159] [client :23707] PHP Fatal error: require(): Failed opening required 'LIBSdispatcher.php' (include_path='/var/www/cake:/var/www/cake/prod/:.:/usr/share/php') in /var/www/cake/prod/webroot/index.php on line 82
猜你喜欢
  • 1970-01-01
  • 2023-03-25
  • 2018-04-19
  • 1970-01-01
  • 2017-05-21
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多