Cakephp 3 giving me Fatal error: Uncaught Error: Class 'Cake\Http\Server' not found

7.1k views Asked by At

I have done a cakephp 2 to cakephp 3 upgrade, and that was causing problems, so I found I had to replace the app/webroot with a new set of files that were part of the cakephp 3 skeleton, but now I am getting this error:

Fatal error: Uncaught Error: Class 'Cake\Http\Server' not found in /usr/share/nginx/html/web/app/webroot/index.php:33 Stack trace: #0 /usr/share/nginx/html/web/index.php(47): require() #1 {main} thrown in /usr/share/nginx/html/web/app/webroot/index.php on line 33

After some research, I found this page: https://api.cakephp.org/3.3/, which shows the classes that should be availabe, and I found that if I go to my_cake_project/web/lib/Cake and run ls I get:

basics.php bootstrap.php config Configure Controller Error I18n Log Network src tests Utility View bin Cache Config Console Core Event LICENSE.txt Model Routing Test TestSuite VERSION.txt

But I am missing several libraries that are supposed to be in CakePHP 3, including the Http folder, and I believe that is why Cake/Http/Server is not found.

I have tracked down the line that is triggering the error to this:

// Bind your application to the server.
$server = new Server(new Application(dirname(__DIR__) . '/config'));

This is in app/webroot/index.php.

I tried splitting that up to:

$a = new Application(dirname(__DIR__) . '/config');
$server = new Server($a);

just for testing, and I found that it is also saying that the Class Application can not be found.

This is the whole file of app/webroot/index.php that I have:

<?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(dirname(__DIR__)) . '/vendors/autoload.php';

use App\Application;
use Cake\Http\Server;

// Bind your application to the server.
$server = new Server(new Application(dirname(__DIR__) . '/config'));

// Run the request/response through the application
// and emit the response.
$server->emit($server->run());

So I must be missing the file for the Application class too

And based on comparing what I have in lib/Cake folder with https://api.cakephp.org/3.3/ I a missing a bunch of cakephp lib folders.

I seem to be missing not just Http, but also:

`Auth`, `Collection`, `Database`, `Datasource`, `Filesystem`, `Form`, `Mailer`, `ORM`, `Shell`, `Utility`, and `Validation`

Why am I missing these?, and where or how can I find and install all the missing libraries into my cakephp appliation?

2

There are 2 answers

0
Volodymyr Butko On

You haven't downloaded all dependencies to vendor folder. I used OpenServer console on Windows and php composer.phar update was helpful for me (I had installed composer locally to my project before). In my opinion, that happened because you had installed the framework instance without Administrator rights.

0
Robin Carlo Catacutan On

I had the same problem, when I created my project ages ago Composer was still at the early stage so I didn't install CakePHP through it.

To fix it I had to copy the composer.json file from the example template here then ran php composer.phar update. Make sure to choose the correct branch where you copy the composer.json file.

Also I used this tool when migrating. You can use this incase the official upgrade tool doesn't work for you.