82

I am getting following error when I open my site which is made using laravel 5

Fatal error: Class 'Illuminate\Foundation\Application' not found in C:\cms\bootstrap\app.php on line 14

I have tried removing vendor folder and composer.lock file and running composer install it's not working I tried running PHP artisan optimize but it shows error

Fatal error: Class'Illuminate\Foundation\Application' not found

Is there any way to solve this problem?

Edited: This problem aroused as soon as I used the php artisan make:model Page command which did create the model but then the above error gets displayed when I access the site Also If use the Laravel's Local Development Server no such problem arises only if I use wamp server

Paulo Boaventura
  • 1,365
  • 1
  • 9
  • 29
xenish
  • 1,384
  • 3
  • 14
  • 17

15 Answers15

110

In my situation, I didn't have the full vendor dependencies in place (composer file was messed up during original install) - so running any artisan commands caused a failure.

I was able to use the --no-scripts flag to prevent artisan from executing before it was included. Once my dependencies were in place, everything worked as expected.

composer update --no-scripts
Daniel Mitchell
  • 1,101
  • 1
  • 6
  • 4
52

Just in case I trip over this error in 2 weeks again... My case: Checkout an existing project via git and pull in all dependencies via composer. Came down to the same error listed within the title of this post.

Solution:

composer dump-autoload
composer install --no-scripts

make sure everything works now as expected (no errors!)

composer update
mwallisch
  • 1,751
  • 2
  • 21
  • 29
  • 1
    This should be the accepted answer, was going around this for about two hours, trying other answers from stack, but this totally solved it. Easy and to the point. Thanks – Migerusantte Oct 31 '17 at 02:40
  • 1
    This works for me, encounter this issues after migrating Laravel website to another server – Adolfo Gomez Nasol Sep 06 '18 at 06:52
  • in my case ," composer dump-autoload" didn't worked but instead "composer install --no-scripts" was so fine! – Ali Safaei Mar 08 '23 at 12:18
8

Something is clearly corrupt in your Laravel setup and it is very hard to track without more info about your environment. Usually these 2 commands help you resolve such issues

php artisan clear-compiled
composer dump-autoload

If nothing else helps then I recommend you to install fresh Laravel 5 app and copy your application logic over, it should take around 15 min or so.

Margus Pala
  • 8,433
  • 8
  • 42
  • 52
6

Easy as this, that worked for my project

  • Delete /vendor folder
  • and execute composer install
  • then run project php artisan serve
Isha
  • 391
  • 3
  • 4
4

In my case composer was not installed in that directory. So I run

composer install

then error resolved.

or you can try

composer update --no-scripts
cd bootstrap/cache/->rm -rf *.php
composer dump-autoload
Santosh Dangare
  • 685
  • 1
  • 4
  • 15
Prajakta Pawar
  • 140
  • 1
  • 8
2

I just fixed this problem (Different Case with same error),
The answer above I tried may not work because My case were different but produced the same error.
I think my vendor libraries were jumbled,
I get this error by:
1. Pull from remote git, master branch is codeigniter then I do composer update on master branch, I wanted to work on laravel branch then I checkout and do composer update so I get the error,

Fatal error: Class 'Illuminate\Foundation\Application' not found in C:\cms\bootstrap\app.php on line 14

Solution: I delete the project on local and do a clone again, after that I checkout to my laravel file work's branch and do composer update then it is fixed.

Calvin
  • 605
  • 10
  • 26
2

I had accidentally commented out:

require __DIR__.'/../bootstrap/autoload.php';

in /public/index.php

When pasting in some debugging statements.

Onshop
  • 2,915
  • 1
  • 27
  • 17
1

For latest laravel version also check your version because I was also facing this error but after update latest php version, I got rid from this error.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Therichpost
  • 1,759
  • 2
  • 14
  • 19
1

run composer require laravel/framework after composer install then php artisan key:generate its work for me in kali linux

Mr. A
  • 71
  • 7
0

please test below solution:

  • first open command prompt cmd ==> window+r and go to the location where laravel installed.

  • try composer require laravel/laravel

Mostafa Norzade
  • 1,578
  • 5
  • 24
  • 40
0

I can't imagine that anyone else reading this is a stupid as I was but just in case... I had accidentally removed "laravel/framework": "^5.6" from my composer.json when resolving merge conflicts.

Frank
  • 243
  • 1
  • 2
  • 14
0

i was having same problem with this error. It turn out my Kenel.php is having a wrong syntax when i try to comply with wrong php8 syntax

The line should be

protected $commands = [
    //
];

instead of

protected array $commands = [
        //
];
0

@kalhan-toress 's comment is what ACTUALLY WORKED FOR ME
remove /bootstrap/start.php,composer.lock, and the vendor and run composer install

Ray Zion
  • 610
  • 10
  • 11
0

In my case, the error was caused on initial deployment because I didn't have a .env file in that directory (because those don't belong on Github where the files were transferred from).

JessycaFrederick
  • 408
  • 3
  • 10
0

check your .env file i think you miss something. Maybe like this

enter image description here

if yes then need to add manually and composer update or install composer