Sling Academy
Home/PHP/How to Run Laravel in Debug/Development Mode

How to Run Laravel in Debug/Development Mode

Last updated: January 18, 2024

Introduction

Laravel, one of the most popular PHP frameworks, is widely admired for its elegance and developer-friendly environment. Running Laravel in debug or development mode is critical during the development process to troubleshoot issues effectively and streamline application development. This tutorial will guide you through enabling and using Laravel’s Debug mode effectively.

Prerequisites

  • A Laravel application
  • Terminal access or SSH for remote servers
  • Code editor of your choice

Step-by-Step Instructions

Step 1: Environment Configuration

When you install Laravel, your project comes with a file named .env. This file contains key-value pairs for configuring your application. To enable debug mode, you must set the APP_DEBUG variable to true.

APP_DEBUG=true

Besides APP_DEBUG, ensure the APP_ENV is set to local, indicating that you’re running the application in a local environment.

APP_ENV=local

Step 2: Error and Exception Handling

In your App/Exceptions/Handler.php, the report and render methods dictate how exceptions are logged and displayed. Laravel traditionally handles this gracefully, but you can customize these as needed for development.

Step 3: Logging

Laravel enables extensive logging through the Monolog library. In your config files, you can specify different types of log channels.

Step 4: Debugging Tools

Laravel Telemetry and third-party packages like Laravel Debugbar can further enhance your debugging experience. Install them via Composer:

composer require barryvdh/laravel-debugbar --dev

Debugbar adds a developer toolbar ideal for monitoring queries, exception handling, and other crucial metrics during development.

Conclusion

Setting up Laravel for development and utilizing built-in and additional tooling provides a robust environment for building high-quality applications efficiently. Remember to turn off debugging features in production to protect sensitive information and maintain performance.

Next Article: How to run Laravel in maintenance mode

Previous Article: Laravel folder structure: Understanding the big picture

Series: Laravel & Eloquent Tutorials

PHP

You May Also Like

  • Pandas DataFrame.value_counts() method: Explained with examples
  • Constructor Property Promotion in PHP: Tutorial & Examples
  • Understanding mixed types in PHP (5 examples)
  • Union Types in PHP: A practical guide (5 examples)
  • PHP: How to implement type checking in a function (PHP 8+)
  • Symfony + Doctrine: Implementing cursor-based pagination
  • Laravel + Eloquent: How to Group Data by Multiple Columns
  • PHP: How to convert CSV data to HTML tables
  • Using ‘never’ return type in PHP (PHP 8.1+)
  • Nullable (Optional) Types in PHP: A practical guide (5 examples)
  • Explore Attributes (Annotations) in Modern PHP (5 examples)
  • An introduction to WeakMap in PHP (6 examples)
  • Type Declarations for Class Properties in PHP (5 examples)
  • Static Return Type in PHP: Explained with examples
  • PHP: Using DocBlock comments to annotate variables
  • PHP: How to ping a server/website and get the response time
  • PHP: 3 Ways to Get City/Country from IP Address
  • PHP: How to find the mode(s) of an array (4 examples)
  • PHP: Calculate standard deviation & variance of an array