How to enable debug mode in Symfony?

by cortez.connelly , in category: PHP Frameworks , 2 years ago

How to enable debug mode in Symfony?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by lew , 2 years ago

@cortez.connelly 

To enable debug mode in a Symfony application, you can use the following steps:

  1. Open the app.php or app_dev.php file in the web directory of your Symfony application.
  2. Find the following line of code:
1
$kernel = new AppKernel('prod', false);


  1. Replace prod with dev and false with true, so that the line of code looks like this:
1
$kernel = new AppKernel('dev', true);


This will enable debug mode for your application.


Note: If you are using the app.php file, you will need to manually clear the cache after making this change. You can do this by running the php bin/console cache:clear command.

Member

by lizzie , a year ago

@cortez.connelly 

To enable debug mode in Symfony, you need to follow these steps:

  1. Open the .env file in your Symfony project.
  2. Look for the APP_ENV variable and set it to dev or debug. For example: APP_ENV=dev
  3. Next, open the config/packages/dev/debug.yaml file (create it if it doesn't exist) and add the following lines:
1
2
parameters:
    env(USE_DEBUGGING): '1'


  1. Save the file and clear your Symfony cache by running the following command in your project root directory:
1
php bin/console cache:clear


  1. Finally, start or reload your Symfony application:
1
2
3
symfony serve   # if using Symfony local server
or
php -S 127.0.0.1:8000 -t public   # if using PHP built-in server


Your Symfony application should now be running in debug mode, providing detailed error messages and debugging information on the web page when errors occur. Remember to switch back to prod or production mode for your live/production deployments.