Laravel error 'ReflectionException' - 'Class App\Http\Kernel does not exist'
Asked Answered
R

5

19

I was trying to go live with a laravel project i developped a year back in school and i ran into some issue. After uploading the whole project on my hosting service's server, i got these errors on my browser as well as on my SSH shell.

Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Http\Kernel does not exist' in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php:779 Stack trace: #0 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('App\Http\Kernel') #1 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(659): Illuminate\Container\Container->build('App\Http\Kernel', Array) #2 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): Illuminate\Container\Container->make('App\Http\Kernel', Array) #3 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(229): Illuminate\Foundation\Application->make('App\Http\Kernel', Array) #4 /home/clients/ffa41f94063 in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 779

I think it could be related to my namespace configuration, because i haven't all understood yet.

Here is my composer.json file :

{
	"name": "laravel/laravel",
	"description": "The Laravel Framework.",
	"keywords": ["framework", "laravel"],
	"license": "MIT",
	"type": "project",
	"require": {
		"laravel/framework": "5.0.*",
		"illuminate/html": "5.*",
		"barryvdh/laravel-dompdf": "0.5.*",
		"guzzlehttp/guzzle": "~4.0"

	},
	"require-dev": {
		"phpunit/phpunit": "~4.0",
		"phpspec/phpspec": "~2.1"
	},
	"autoload": {
		"classmap": [
			"database"
		],
		"psr-4": {
			"App\\": "myforms/app/"
		}
	},
	"autoload-dev": {
		"classmap": [
			"tests/TestCase.php"
		]
	},
	"scripts": {
		"post-install-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-update-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-create-project-cmd": [
			"php -r \"copy('.env.example', '.env');\"",
			"php artisan key:generate"
		]
	},
	"config": {
		"preferred-install": "dist"
	}
}

What I have already done :

  • Delete /vendor and make a new install with composer install
  • composer dump-autoload
  • composer update btw, I get the error when I insert the composer update

Please inform me if i should post another file that could be useful.

Thanks in advance for your help.

Rubicund answered 12/8, 2016 at 13:17 Comment(4)
What error does composer update generate?Unregenerate
check this run composer dump-autoloadDardanus
@Unregenerate it generates the one i posted earlier. but it adds a line : Script php artisan clear-compiled handling the post-update-cmd event returned wi th error code 255Rubicund
@pari thanks for the link, what does he means by saying check if bindings in bootstrap/app.php are correct.Rubicund
A
30

In composer.json change:

 "psr-4": {
        "App\\": "myforms/app/"
    } 

to:

 "psr-4": {
        "App\\": "app/"
    }

On the server, in your source directory, run composer update then composer dump-autoload

PSR-4 in Laravel looks for namespaces relative to the root of the project

Asmodeus answered 12/8, 2016 at 14:54 Comment(1)
After changing my laravel application Name using the command line (php artisan app:name "my name") to test if things goes fine. the application collapsed and destroyed. and thanks to the 'git ', I discarded the changes. but i did face the same problem. the CL (composer dump-autoload) saved my day. Thanks.Naval
E
3

Check if console/kernel.php is inside of app-folder, if not it might be inside of your laravelApp.

If so, move console/kernel.php to app-folder.

Escort answered 13/5, 2020 at 13:36 Comment(1)
Damn I found this question from google and then I see the answer from 4 secs agoLandau
T
2

With the help of the other answers here, I realised I'd just missed a change when manually updating from Laravel 5.5 to 5.7

In composer.json, I'd missed this from the autoload block:

"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    ...
},

If you're using version control, run composer update on your dev machine to update composer.lock. Then on your production server, you should only need to run composer install

Trillbee answered 13/10, 2022 at 21:43 Comment(0)
S
1

In my case composer.json was missing propper bracket closing "{ }" and line with "psr-4" was in wrong json segment.

  1. Check composer.json for proper align of "psr-4" it should be child of "autoload" section.
  2. Remove vendor
  3. composer install

OK

Salify answered 16/3, 2020 at 11:15 Comment(0)
C
0

{
	"name": "laravel/laravel",
	"description": "The Laravel Framework.",
	"keywords": ["framework", "laravel"],
	"license": "MIT",
	"type": "project",
	"require": {
		"laravel/framework": "5.0.*",
		"illuminate/html": "5.*",
		"barryvdh/laravel-dompdf": "0.5.*",
		"guzzlehttp/guzzle": "~4.0"

	},
	"require-dev": {
		"phpunit/phpunit": "~4.0",
		"phpspec/phpspec": "~2.1"
	},
	"autoload": {
		"classmap": [
			"database"
		],
		"psr-4": {
			"App\\": "myforms/app/"
		}
	},
	"autoload-dev": {
		"classmap": [
			"tests/TestCase.php"
		]
	},
	"scripts": {
		"post-install-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-update-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-create-project-cmd": [
			"php -r \"copy('.env.example', '.env');\"",
			"php artisan key:generate"
		]
	},
	"config": {
		"preferred-install": "dist"
	}
}
Corrupt answered 13/4, 2020 at 21:22 Comment(2)
Can you add a comment about what you've changed?Chamblee
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.Eupheemia

© 2022 - 2024 — McMap. All rights reserved.