How to Enable and Disable Debug Mode in Laravel
In this post, we’re gonna be looking at how to enable and disable debug mode in Laravel.
Debug mode provides you with detailed error messages, stack traces and other useful information that you need in order to detect and remove potential errors from your application.
Let’s take this for example.
There is clearly an error in my app but because I don’t have the debug mode enabled, all I see is this generic 500 error.
Now let’s go ahead and set debug mode to
true so we can see a more detailed error message.
Enable Debug Mode
To enable debug mode, open the
.env file which can be found in the root directory of your Laravel app.
APP_DEBUG variable to
In order for this change to take effect, we have to clear the configuration cache.
Open up your terminal and run
php artisan config:cache
This will first clear the configuration cache and it will then recache it.
Now let’s go back to the app and see if I have a more detailed error message.
And that’s right!
I now have more details about the error and in this particular case I am able to easily fix it by importing the missing
Disable Debug Mode
To disable debug mode, simply set the
APP_DEBUG environment variable to
One thing you need to be very careful about is to not have the debug mode enabled in the production environment.
You don’t want your sensitive data to be exposed to the end-users!
So before you push your app to production, do one last check-up to make sure the debug mode is disabled.
Familiarize with config/app.php
One more thing worth mentioning is the
debug option here uses the
APP_DEBUG environment variable to set the debug mode on or off.
The second parameter is the default option, which is
false in my case.
So that means if we don’t have a
APP_DEBUG environment variable set in the
.env file, the debug mode will be set to
false by default.
Let me know what you think about this article through comments below, or on Twitter at @pelu_carol.
If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.