Skip to content

How to Enable and Disable Debug Mode in Laravel

Laravel Enable Disable Debug Mode

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.

500 Internal Server Erorr Laravel Debug Mode Disabled

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.

Set the APP_DEBUG variable to true.

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.

Laravel Debug Mode Enabled

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 Log Class.

Disable Debug Mode

To disable debug mode, simply set the APP_DEBUG environment variable to false.

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 config/app.php file.

Laravel configuration app file

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.

That’s all!

Happy coding!


Let me know what you think about this article in the comments section below.

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.   
  

Comments