Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Symfony stops with Class DebugBundle not found after a production install

Your error

Uncaught Error: Class "Symfony\Bundle\DebugBundle\DebugBundle" not found1 more line it can show

Fix it fast

Most common cause, 1 of 3

Composer's post-install scripts run in dev during composer install --no-dev

Export APP_ENV=prod in the same shell before running Composer, so the scripts boot the prod environment, which does not load dev-only bundles.

Fix
export APP_ENV=prod
composer install --no-dev --optimize-autoloader
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Uncaught Error: Class "Symfony\Bundle\DebugBundle\DebugBundle" not found means Symfony 7.4 or 8.1 booted in the dev environment, where config/bundles.php enables DebugBundle, on a machine where composer install --no-dev skipped that package. Export APP_ENV=prod before Composer, set APP_ENV=prod for the web server, or install symfony/debug-bundle where dev mode is intended.

  • Applies to Symfony 7.4 LTS, Symfony 8.1, PHP 8.4, PHP 8.5, Composer 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Find out which environment Symfony boots in and whether the bundle's package is installed. A dev environment with the package missing is the whole story; the only question is where the dev value comes from.

Run this first
grep -n "APP_ENV" .env .env.local 2>/dev/null
printenv APP_ENV
grep -n "DebugBundle" config/bundles.php
composer show symfony/debug-bundle

Then find the line you see in this list and open its fix:

  1. 1Composer's post-install scripts run in dev during composer install --no-devThe error appears in the output of composer install --no-dev, when the auto-scripts run cache:clear
  2. 2The production server still runs with APP_ENV=devComposer succeeded, but the site or bin/console fails with the error, and APP_ENV is dev in .env with nothing overriding it
  3. 3You want dev mode, but symfony/debug-bundle is not installedA development machine or test box meant to run in dev, where composer show reports the package as not found

What does the error look like?

  • Uncaught Error: Class "Symfony\Bundle\DebugBundle\DebugBundle" not found
  • Uncaught Error: Class "Symfony\Bundle\WebProfilerBundle\WebProfilerBundle" not found

Cause 1 of 3

Composer's post-install scripts run in dev during composer install --no-dev

You seeThe error appears in the output of composer install --no-dev, when the auto-scripts run cache:clear

Check

Class DebugBundle not found during composer install --no-dev means the post-install-cmd scripts booted the kernel in the dev environment. --no-dev keeps development packages such as symfony/debug-bundle out, while bundles.php still enables DebugBundle for dev. Symfony's deployment guide names this exact case: a class not found error during this step.

Check
composer install --no-dev --optimize-autoloader

Fix

Export APP_ENV=prod in the same shell before running Composer, so the scripts boot the prod environment, which does not load dev-only bundles.

Fix
export APP_ENV=prod
composer install --no-dev --optimize-autoloader

Verify

Composer finishes, including the cache:clear script, without the error.

Verify
APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear

Confirmed by symfony.com

Did this fix it?

Cause 2 of 3

The production server still runs with APP_ENV=dev

You seeComposer succeeded, but the site or bin/console fails with the error, and APP_ENV is dev in .env with nothing overriding it

Check

Class DebugBundle not found on a running site means the web server or the console boots Symfony with APP_ENV=dev, so bundles.php asks for a bundle that was never installed. APP_ENV comes from the .env files unless a real environment variable is set, and real environment variables always win over the files.

Check
grep -n "APP_ENV" .env .env.local 2>/dev/null
APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear

Fix

Set APP_ENV=prod as a real environment variable in the web server or PHP-FPM configuration, or put APP_ENV=prod in .env.local on that machine. Then clear the prod cache.

Fix
# .env.local on the production machine (not committed)
APP_ENV=prod
APP_DEBUG=0

APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear

Verify

The console runs without APP_ENV on the command line, and the site answers again.

Verify
php bin/console cache:clear
curl -I https://example.com/

Confirmed by symfony.com

Did this fix it?

Cause 3 of 3

You want dev mode, but symfony/debug-bundle is not installed

You seeA development machine or test box meant to run in dev, where composer show reports the package as not found

Check

Class DebugBundle not found in a deliberate dev environment means the bundle is enabled in config/bundles.php but its package is not in vendor, for example after composer install --no-dev on that machine or after the package was removed from composer.json.

Check
composer show symfony/debug-bundle
grep -n "debug-bundle" composer.json

Fix

Install the package as a development dependency, as the VarDumper docs instruct, or delete the DebugBundle line from config/bundles.php if you no longer want it.

Fix
composer require --dev symfony/debug-bundle
composer install

Verify

composer show prints the package, and the dev site loads with dump() output in the toolbar.

Verify
composer show symfony/debug-bundle

Confirmed by symfony.com

Did this fix it?

How do I stop it coming back?

  • Put export APP_ENV=prod at the top of the deploy script, before composer install --no-dev.
  • Set APP_ENV=prod as a real environment variable in the production PHP-FPM or web server config, not only in a .env file.
  • Keep dev-only bundles marked ['dev' => true] in config/bundles.php, and their packages in require-dev.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Spotless Laundry, EZ Estimater.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.