Symfony4项目WebProfiler加载404错误求助
Hey there, let's fix that Web Profiler 404 error in your Symfony 4 project. I've run into this exact issue before, so here are the most common fixes to try:
First, check if the dev routing config for the profiler is in place. Navigate to config/routes/dev/web_profiler.yaml and make sure it contains this:
web_profiler_wdt: resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml' prefix: /_wdt web_profiler_profiler: resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml' prefix: /_profiler
If this file is missing, reinstall the bundle with:
composer require --dev symfony/web-profiler-bundle
The Web Profiler only works in the dev environment. Check your .env file and confirm:
APP_ENV=dev
If you're using a server like Apache/Nginx, make sure the APP_ENV environment variable is set to dev (some servers override this in their configs).
- Built-in Server: If you're using Symfony's built-in server, run it from your project root with:
Or the PHP built-in server:symfony server:start
Make sure you're pointing directly to thephp -S localhost:8000 -t publicpublicdirectory as the document root. - Apache/Nginx: Ensure your web server's document root is set to the
publicfolder, and that rewrite rules are working. For Apache, the default.htaccessinpublicshould handle this—don't delete or modify it unless you know what you're doing. For Nginx, double-check your config includes rules to forward all requests toindex.php.
Cached routing data can sometimes cause issues. Clear the dev environment cache with:
php bin/console cache:clear --env=dev
Check config/bundles.php to make sure the bundle is enabled for the dev environment:
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
If this line is missing, add it and then re-run the cache clear command.
After trying these steps, refresh your page and click the "Open Web Profiler" link again—it should load correctly now!
内容的提问来源于stack exchange,提问作者Sander Bakker

