Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Cookbook
  4. Bundles
  5. How to Install 3rd Party Bundles
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

Table of Contents

  • A) Add Composer Dependencies
    • 1) Find out the Name of the Bundle on Packagist
    • 2) Install the Bundle via Composer
  • B) Enable the Bundle
  • C) Configure the Bundle
  • Other Setup

How to Install 3rd Party Bundles

Edit this page

Warning: You are browsing the documentation for Symfony 2.3, which is no longer maintained.

Read the updated version of this page for Symfony 6.3 (the current stable version).

How to Install 3rd Party Bundles

Most bundles provide their own installation instructions. However, the basic steps for installing a bundle are the same:

  • A) Add Composer Dependencies
  • B) Enable the Bundle
  • C) Configure the Bundle

A) Add Composer Dependencies

Dependencies are managed with Composer, so if Composer is new to you, learn some basics in their documentation. This involves two steps:

1) Find out the Name of the Bundle on Packagist

The README for a bundle (e.g. FOSUserBundle) usually tells you its name (e.g. friendsofsymfony/user-bundle). If it doesn't, you can search for the bundle on the Packagist.org site.

Tip

Looking for bundles? Try searching at KnpBundles.com: the unofficial archive of Symfony Bundles.

2) Install the Bundle via Composer

Now that you know the package name, you can install it via Composer:

1
$ composer require friendsofsymfony/user-bundle

This will choose the best version for your project, add it to composer.json and download its code into the vendor/ directory. If you need a specific version, include it as the second argument of the composer require command:

1
$ composer require friendsofsymfony/user-bundle "~2.0"

B) Enable the Bundle

At this point, the bundle is installed in your Symfony project (in vendor/friendsofsymfony/) and the autoloader recognizes its classes. The only thing you need to do now is register the bundle in AppKernel:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new FOS\UserBundle\FOSUserBundle(),
        );

        // ...
    }
}

In a few rare cases, you may want a bundle to be only enabled in the development environment. For example, the DoctrineFixturesBundle helps to load dummy data - something you probably only want to do while developing. To only load this bundle in the dev and test environments, register the bundle in this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
        }

        // ...
    }
}

C) Configure the Bundle

It's pretty common for a bundle to need some additional setup or configuration in app/config/config.yml. The bundle's documentation will tell you about the configuration, but you can also get a reference of the bundle's configuration via the config:dump-reference command:

1
$ app/console config:dump-reference AsseticBundle

Instead of the full bundle name, you can also pass the short name used as the root of the bundle's configuration:

1
$ app/console config:dump-reference assetic

The output will look like this:

1
2
3
4
5
6
7
8
9
10
11
assetic:
    debug:                '%kernel.debug%'
    use_controller:
        enabled:              '%kernel.debug%'
        profiler:             false
    read_from:            '%kernel.root_dir%/../web'
    write_to:             '%assetic.read_from%'
    java:                 /usr/bin/java
    node:                 /usr/local/bin/node
    node_paths:           []
    # ...

Other Setup

At this point, check the README file of your brand new bundle to see what to do next. Have fun!

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:
    Symfony Code Performance Profiling

    Symfony Code Performance Profiling

    Peruse our complete Symfony & PHP solutions catalog for your web development needs.

    Peruse our complete Symfony & PHP solutions catalog for your web development needs.

    Symfony footer

    ↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

    Avatar of Kamil Pešek, a Symfony contributor

    Thanks Kamil Pešek (@kamil_pesek) for being a Symfony contributor

    2 commits • 22 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • Symfony at a Glance
      • Symfony Components
      • Case Studies
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • SymfonyConnect
      • Support
      • How to be Involved
      • Code of Conduct
      • Events & Meetups
      • Projects using Symfony
      • Downloads Stats
      • Contributors
      • Backers
    • Blog

      • Events & Meetups
      • A week of symfony
      • Case studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Documentation
      • Living on the edge
      • Releases
      • Security Advisories
      • SymfonyInsight
      • Twig
      • SensioLabs
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Deployed on

    Follow Symfony

    Search by Meilisearch