21

I developed laravel app locally and uploaded in shared hosting.

While hosting I changed the database name and username of mysql in the .env and the config/database files.

But in remote its still using the old db name and user which is found in the bootstrap/cache/config file.

So how to clean the bootstrap/cache/config.php file?

Rahul
  • 18,271
  • 7
  • 41
  • 60
Abel D
  • 1,040
  • 1
  • 18
  • 30

8 Answers8

58

If you are trying to clear configuration cache, which it sounds like you are. You need to run:

php artisan config:clear

At some point, you probably ran php artisan config:cache which generated a cached version of your config file, and this file is not cleared with php artisan cache:clear

Rahul
  • 18,271
  • 7
  • 41
  • 60
Tommy May
  • 1,100
  • 12
  • 13
35

I tried all the above options but nothing works.

I manually removed from bootstrap/cache/config.php. And it works. This is the Ultimate solution.

Rahul
  • 18,271
  • 7
  • 41
  • 60
26

I just stumbled into this while building automated deployment in AWS. The problem with Laravel is that artisan commands also use the cache. Now if you deploy the new version of your application you may have outdated entries in the cache which in turn will make the artisan command crash i.e. cannot find some class that was cached but no longer exist. Therefore you either need to:

  1. Clear cache before you deploy the application
php artisan cache:clear
  1. Clear cache manually
rm -rf bootstrap/cache/*.php

Finally you want to run optimize command which will re-build your configuration cache, bootstrap file cache and route caches.

php artisan optimize
Community
  • 1
  • 1
Juha Vehnia
  • 1,255
  • 12
  • 15
9

Use php artisan cache:clear to flush the application's cache.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
5
php artisan config:clear

Or you can just manually delete bootstrap/config.php, which is what artisan does after all.

See: vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigClearCommand.php

Lucas Bustamante
  • 15,821
  • 7
  • 92
  • 86
4

Here is the Tip,

  1. Flushing Application cache

    • Use php artisan cache:clear to flush the application cache or php artisan cache:forget to discard specific cache.
    • You can use php artisan config:clear to clear cached configuration of application.
  2. Removing Blade Templates cache

    You can use php artisan view:clear to clear all compiled views.

  3. Application Bootstrap cache

    If you want to clear the application bootstraper cache, php artisan optimize:clear will help you.

  4. Route Cache

    There also a command to clear the route cache as php artisan route:clear.

  5. Events and Listeners cache

    For events and listeners cache you can use php artisan event:clear

if you still stuck in finding helpful commands, you can run php artisan list and it will list out every command with its description. look for a specific thing you want to perform. if you need migration-related command, you can look in migration.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
3

The solution for me was to remove the files in the bootstrap/cache/ directory and then delete the vendor folder. Re-run composer install and then composer dump-autoload and the above campaigns should run fine. Deleting the vendor folder and re-running composer install was the missing link for me

Connor Leech
  • 18,052
  • 30
  • 105
  • 150
  • This did not work for me. My config file is gone in bootstrap and I'm sill getting the error. I don't get it. – mcadio Sep 03 '22 at 14:29
2

You can use:

Laravel 4 : php artisan cache:clear

also for laravel 5(not tested),

Illuminate\Cache\FileStore has the function flush

Cache::flush();

also,

use Doctrine\Common\Cache\CacheProvider as DoctrineCache;

DoctrineCache::flushAll();
Ajit Kumar Singh
  • 357
  • 2
  • 11
  • For laravel 5. where do i run this command from. Shall i create a closure in routes.php and run from there – Abel D Nov 20 '15 at 09:38
  • php artisan cache:clear has to be executed from command prompt. You will have to navigate to your root folder of project, to execute it. For laravel 5, it is argued that one does not need to clear the cache. Yet if you wanna try, use it in controller. – Ajit Kumar Singh Nov 20 '15 at 09:40