Debug mode helps you find and fix errors in your Laravel app by showing detailed error messages.
When you are building a new feature and want to see errors clearly.
When something is not working and you need to understand why.
When you want to check the details of exceptions or bugs.
When testing your app locally before making it live.
Syntax
Laravel
APP_DEBUG=true
This is set in the .env file at the root of your Laravel project.
Set APP_DEBUG=false in production to hide error details from users.
Examples
This shows detailed error messages in your browser.
Laravel
# Enable debug mode
APP_DEBUG=true
This hides error details and shows a generic error page instead.
Laravel
# Disable debug mode
APP_DEBUG=false
Sample Program
This route causes a division by zero error. If APP_DEBUG=true, Laravel shows a detailed error page. If false, it shows a simple error message.
Laravel
<?php
// routes/web.php
use Illuminate\Support\Facades\Route;
Route::get('/debug-example', function () {
// This will cause an error if debug mode is on
return1 / 0;
});
OutputSuccess
Important Notes
Always turn off debug mode (APP_DEBUG=false) on live sites to protect sensitive info.
After changing APP_DEBUG, clear config cache with php artisan config:clear to apply changes.
Summary
Debug mode shows detailed error info to help fix bugs.
Set APP_DEBUG=true in .env to enable it.
Turn it off in production for security by setting APP_DEBUG=false.
Practice
(1/5)
1. What does setting APP_DEBUG=true in Laravel's .env file do?
easy
A. Shows detailed error messages to help find bugs
B. Disables all error messages
C. Automatically fixes bugs in the code
D. Prevents the application from running
Solution
Step 1: Understand the purpose of APP_DEBUG
APP_DEBUG controls whether Laravel shows detailed error messages or not.
Step 2: Effect of setting APP_DEBUG=true
When true, Laravel shows detailed error info to help developers find and fix bugs.
Final Answer:
Shows detailed error messages to help find bugs -> Option A
Quick Check:
APP_DEBUG=true means detailed errors shown [OK]
Hint: True means show errors, false hides them [OK]
Common Mistakes:
Thinking it fixes bugs automatically
Believing it disables errors
Confusing it with app running status
2. Which of the following is the correct way to enable debug mode in Laravel?
easy
A. Set APP_DEBUG=false in .env
B. Set APP_DEBUG=true in .env
C. Add debug_mode=on in config/app.php
D. Run php artisan debug:on in terminal
Solution
Step 1: Locate where debug mode is set
Laravel uses the .env file to set environment variables like APP_DEBUG.
Step 2: Correct value to enable debug
Setting APP_DEBUG=true enables debug mode; false disables it.
Final Answer:
Set APP_DEBUG=true in .env -> Option B
Quick Check:
Enable debug by APP_DEBUG=true [OK]
Hint: Enable debug by setting APP_DEBUG=true in .env [OK]
Common Mistakes:
Setting APP_DEBUG=false to enable debug
Trying to enable debug in config/app.php
Using artisan commands that don't exist
3. Given the following .env setting: APP_DEBUG=false What will Laravel show when an error occurs?
medium
A. A detailed error page with stack trace
B. The application will crash without any message
C. A simple generic error page without details
D. Laravel will automatically fix the error
Solution
Step 1: Check APP_DEBUG value
APP_DEBUG is set to false, which disables detailed error messages.
Step 2: Laravel's behavior with APP_DEBUG=false
Laravel shows a simple generic error page to avoid exposing sensitive info.
Final Answer:
A simple generic error page without details -> Option C