Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Cookbook
  4. Bundles
  5. How to install 3rd party Bundles
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Table of Contents

  • Add Composer Dependencies
  • Enable the Bundle
  • Configure the Bundle
  • Other Setup

How to install 3rd party Bundles

Edit this page

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

Read the updated version of this page for Symfony 6.2 (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.

Add Composer Dependencies

Starting from Symfony 2.1, dependencies are managed with Composer. It's a good idea to learn some basics of Composer in their documentation.

Before you can use Composer to install a bundle, you should look for a Packagist package of that bundle. For example, if you search for the popular FOSUserBundle you will find a package called friendsofsymfony/user-bundle.

Note

Packagist is the main archive for Composer. If you are searching for a bundle, the best thing you can do is check out KnpBundles, it is the unofficial archive of Symfony Bundles. If a bundle contains a README file, it is displayed there and if it has a Packagist package it shows a link to the package. It's a really useful site to begin searching for bundles.

Now that you have the package name, you should determine the version you want to use. Usually different versions of a bundle correspond to a particular version of Symfony. This information should be in the README file. If it isn't, you can use the version you want. If you choose an incompatible version, Composer will throw dependency errors when you try to install. If this happens, you can try a different version.

In the case of the FOSUserBundle, the README file has a caution that version 1.2.0 must be used for Symfony 2.0 and 1.3+ for Symfony 2.1+. Packagist displays example require statements for all existing versions of a package. The current development version of FOSUserBundle is "friendsofsymfony/user-bundle": "2.0.*@dev".

Now you can add the bundle to your composer.json file and update the dependencies. You can do this manually:

  1. Add it to the composer.json file:

    1
    2
    3
    4
    5
    6
    7
    {
        ...,
        "require": {
            ...,
            "friendsofsymfony/user-bundle": "2.0.*@dev"
        }
    }
  2. Update the dependency:

    1
    $ php composer.phar update friendsofsymfony/user-bundle

    or update all dependencies

    1
    $ php composer.phar update

Or you can do this in one command:

1
$ php composer.phar require friendsofsymfony/user-bundle:2.0.*@dev

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(),
        );

        // ...
    }
}

Configure the Bundle

Usually a bundle requires some configuration to be added to app's app/config/config.yml file. The bundle's documentation will likely describe that configuration. But you can also get a reference of the bundle's config via the config:dump-reference command.

For instance, in order to look the reference of the assetic config you can use this:

1
$ app/console config:dump-reference AsseticBundle

or this:

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.

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

Measure & Improve Symfony Code Performance

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

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

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

Avatar of David Baucum, a Symfony contributor

Thanks David Baucum for being a Symfony contributor

1 commit • 2 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 Algolia