You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Symfony4安装EasyAdminBundle后后台访问出现404问题求助

Symfony4 - EasyAdminBundle 404 Error Despite Existing Route

Let's troubleshoot this step by step—this kind of issue is super common when setting up EasyAdmin for the first time, so don't feel frustrated!

1. Double-check Your Entity Configuration

First, make sure your App\Entity\Command class actually exists and is properly set up:

  • Verify the file is located at src/Entity/Command.php
  • Confirm the namespace at the top of the file is namespace App\Entity;
  • Critical: Ensure the class has a correctly configured primary key (EasyAdmin requires this to load the entity interface). For example:
    // src/Entity/Command.php
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\Entity(repositoryClass="App\Repository\CommandRepository")
     */
    class Command
    {
        /**
         * @ORM\Id
         * @ORM\GeneratedValue
         * @ORM\Column(type="integer")
         */
        private $id;
    
        // ... add other fields, getters, and setters here
    }
    

A missing or misconfigured primary key is one of the most frequent causes of this 404.

2. Clear Your Symfony Cache

Symfony caches configuration changes even in development mode. Run this command to wipe the cache and force it to reload your updated settings:

php bin/console cache:clear

If you're testing in production mode, add the environment flag:

php bin/console cache:clear --env=prod

3. Verify the Bundle is Enabled

Check if EasyAdminBundle is properly registered in config/bundles.php. You should see this line in the returned array:

EasyCorp\EasyAdminBundle\EasyAdminBundle::class => ['all' => true],

If it's missing, add it and run composer dump-autoload to refresh the bundle registry.

4. Check Your URL and Server Rewrite Rules

  • Try accessing both /admin (without trailing slash) and /admin/ (with trailing slash)—sometimes server rewrite rules handle one but not the other.
  • For Apache: Ensure your public/ directory has a valid .htaccess file (Symfony generates this by default) with rules to redirect requests to index.php.
  • For Nginx: Confirm your server block includes the correct try_files directive to route all requests through Symfony's front controller:
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    

5. Recheck YAML Indentation

YAML is extremely sensitive to whitespace. Double-check that your easy_admin section in framework.yaml is properly indented (no extra spaces, consistent indentation level relative to other root keys like framework). Your current config looks correct, but a tiny indentation mistake can break the entire setup.


内容的提问来源于stack exchange,提问作者D. Schreier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:53:39