58

It is written in Laravel 5 documentation that php artisan config:cache stores all the app configuration into one single file which makes the application load faster.

I want to know two things:

The first thing is, how to force Laravel to stop caching my app configurations? For example, I want Laravel to read the name of my database and the password from the .env file or from the database.php configuration file, not from the cached data.

The second thing is, where does Laravel store this cached configuration file, so that I can delete it when needed? I know there is an Artisan command for that, which is php artisan config:clear, but I want to know where the file stored.

2540625
  • 11,022
  • 8
  • 52
  • 58
wessodesigner
  • 4,485
  • 3
  • 16
  • 9

2 Answers2

68

You can't stop the caching of config files since it doesn't happen automatically. The only thing you need to do, is not call config:cache.

The file itself can be found in bootstrap/cache/config.php.

Note that the location of the compiled config file has changed recently. Yours might also be in vendor/config.php or storage/framework/config.php. With a fresh install or if you run composer update the file should be in bootstrap/cache though.

lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
  • Work for me, it's hard coded in Laravel 5 , at [ vendor/config.php ] – Ihab Shoully Nov 15 '15 at 14:06
  • 32
    If you did however call `config:cache` during local development, you can undo this by deleting the `bootstrap/cache/config.php` file. Otherwise, you might experience that calling `getenv()` will not return the desired values – Sven P Mar 11 '16 at 08:50
  • We had this issue when we've added `config:cache` as post deployment hook in envoyer (for production server). Oddly enough, somehow it did not take all the values from the .env file. – Attila Fulop Nov 04 '16 at 09:12
  • Im using Laravel 5.6 and my config doesn't change even after `rm bootstrap/cache/config.php`. – Cobolt Aug 01 '18 at 08:27
  • 3
    I ended up doing `$config =require base_path('config/services.php');`. We've struggled with this a few times in the past. Only laravel can make something this simple problematic. – Cobolt Aug 01 '18 at 08:51
  • Calling `php artisan config:clear` will also fix the issue until you call `php artisan config:cache`. However if you have a large team... it may be wise just to instill some checkers to make sure the cache is always there and always up to date. – Spencer O'Reilly Jan 29 '20 at 22:25
-1

As per the post here: https://github.com/laravel/framework/issues/2501

"Change cache driver to array for the local environment."

For me this involves adding CACHE_DRIVER=array to my .env file. This is then picked up by my config/cache.php file which includes the line: 'default' => env('CACHE_DRIVER', 'file'),

Obviously you could change it directly in the config/cache.php but I'd prefer to use the .env file so I can disable it for development sites and enable for production.

Lex
  • 113
  • 9
  • 1
    This is completely unrelated. The settings in `config/cache.php` relate to Laravel's cache feature as documented [here](https://laravel.com/docs/master/cache), which is *not* used when caching the configuration itself. The configuration is only ever cached in the form of PHP code inside `bootstrap/cache/config.php`. – tjbp Jun 09 '20 at 20:06