Step By Step installation and Configuration Guide of SonataAdminBundle

A complete guide to installing SonataAdminBundle via composer and configure bundle into Symfony project.

Today we will learn how to setup SonataAdminBundle into the Symfony2 project. SonataAdminBundle allows us to create a complete backend for our site. With SonataAdminBundle we can easily setup backend by typing some commands in command prompt. SonataAdminBundle can be installed at any moment during a project’s lifecycle, whether it’s a clean Symfony2 installation or an existing project. So, Now let’s start with installing Sonata Bundle into our Symfony project.

Download the Admin Bundle

To download the Sonata Admin Bundle we use below command that will be executed through composer. So to use this command you need to install composer first.

$ composer require sonata-project/admin-bundle 2.4.*@dev

Once you run this command on command prompt it downloads all dependent bundles:

- knplabs/knp-menu 
- knplabs/knp-menu-bundle 
- cocur/slugify 
- sonata-project/core-bundle 
- sonata-project/cache 
- sonata-project/block-bundle 
- sonata-project/exporter 
- twig/extensions
- sonata-project/admin-bundle

How to Enable downloaded Bundle

When all Admin Bundle has been downloaded then you can enable the bundle by adding the following line into app/AppKernel.php file.


use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
    public function registerBundles()
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),

        if (in_array($this--->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();

        return $bundles;

    public function registerContainerConfiguration(LoaderInterface $loader)

Configure Sonata Block

After enabling Sonata Admin Bundle you will need to configure SonataAdminBundle dependencies. SonataAdminBundle also downloads the SonataBlockBundle which is used to create Admin dashboard. So, Now we will configure our SonataBlockBundle into our project. To config this bundle we will use app/config/config.yml file.

# app/config/config.yml

    default_contexts: [cms]

        # enable the SonataAdminBundle block
            contexts:   [admin]

Import Admin Routing

Sonata Admin Bundle is now properly downloaded and configured. But now if you want to use access your Admin first you need import routing into main routing.yml.

# app/config/routing.yml
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /admin

Install Admin Assets and Cleaning

Now your Admin is ready to use but before go on browser we will run some basic command that basically used after you installed any new bundle.
First is installing bundle assets.

$ php app/console assets:install

and the Second is clear: cache which deletes all older cache from the project

$ php app/console cache:clear

So, Finally, your Admin is ready to use. Now you can view your admin dashboard into the browser.

Write a Reply or Comment

Your email address will not be published. Required fields are marked *