Open Laboratory for Technocrats

Grab the developer role, learn concepts & prepare with senior software engineers to get solutions for problems in a software job. Coding and Programming Solutions crafted for you.

Laravel - env file not working - solution

Laravel - env file not working - solution
Laravel - env file not working - solution

I was playing around the Laravel which is a nice framework for PHP developers. It has awesome features. If you are a PHP developer you must try it.

Now let's dive into the problem which our developer faced while developing the application in this framework.

After developing the application we were on our testing server but our config files which is DOT ENV in our case was not loading the data which we have put it on the system.

We had config URLs, custom rules and another key which needs to be according to the services which we have used in our case.

The application is up and running on our server and can be accessed but the custom rules and config URLs are pointing to old env files WHY?

Reason for the same is Cache.

Laravel has cache system enabled which keeps the cache of various things that need to be updated or clear before you can check the new details. Even if you are working on the local system you need to clear the cache to reflect the changes in the application.

For so we need to use following commands on our CLI:

  • Config caching
For config files related issue we need to play around Config cache
php artisan config:cache
Above command will collect all the different config files to a single file and cache the details at single place
php artisan config:clear
Above command will clear the config cache and will update the cache with the new details in the config files

  • Routes caching
For routes related issue we need to play around Route cache
php artisan route:cache
Above command will collect all routes and place the cache of all the routes for faster URL mapping.
php artisan route:clear
Above command will clear the cache for routes on the application and reload the fresh details for the route cache

  • Classmap optimization
For Classmap optimization, we might need to do it with force
php artisan optimize --force

Keep Learning and Keep Coding :)


Top #3 Articles