Search code examples
cakephpcakephp-3.0dispatcherinternal-server-error

CakePHP 3 : Class 'Cake\Routing\DispatcherFactory' not found


I have developed an application in CakePHP 3. It was working fine in my localhost server but when I uploaded it to shared hosting it started giving 500 Internal server error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at admin@main-hosting.eu to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

I tried all solutions on google but nothing helped. Then I located php error log and found these lines in it.

[19-Jun-2016 18:29:08 UTC] PHP Fatal error:  Uncaught Error: Class 'Cake\Routing\DispatcherFactory' not found in /home/username/public_html/webroot/index.php:33
Stack trace:
#0 {main}
  thrown in /home/username/public_html/webroot/index.php on line 33

Content of /webroot/index.php is

<?php
/**
 * The Front Controller for handling every request
 *
 * 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
 * @since         0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
// for built-in server
if (php_sapi_name() === 'cli-server') {
    $_SERVER['PHP_SELF'] = '/' . basename(__FILE__);

    $url = parse_url(urldecode($_SERVER['REQUEST_URI']));
    $file = __DIR__ . $url['path'];
    if (strpos($url['path'], '..') === false && strpos($url['path'], '.') !== false && is_file($file)) {
        return false;
    }
}
require dirname(__DIR__) . '/config/bootstrap.php';

use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\DispatcherFactory;

$dispatcher = DispatcherFactory::create();    // Line 33
$dispatcher->dispatch(
    Request::createFromGlobals(),
    new Response()
);

What is wrong here ?


Solution

  • If you are using shared hosting then please check for file and folder permissions:

    1. All files in your cake project must have 644 permission

    644 means that files are readable and writeable by the owner of the file and readable by users in the group owner of that file and readable by everyone else.

    1. All Folder in your cake project must have 755 permission

    755 is the same thing, it just has the execute bit set for everyone. The execute bit is needed to be able to change into the directory. This is why directories are commonly set to 755.

    1. Check All Extension and Configuration to run your Cake project and also check whether rewrite module is working or not.

    Hope this works for you...