.. index:: single: Bundle; Installation
Most bundles provide their own installation instructions. However, the basic steps for installing a bundle are the same.
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 packaged 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 achive 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:
Add it to the composer.json file:
{ ..., "require": { ..., "friendsofsymfony/user-bundle": "2.0.*@dev" } }
Update the dependency:
$ php composer.phar update friendsofsymfony/user-bundle
or update all dependencies
$ php composer.phar update
Or you can do this in one command:
$ php composer.phar require friendsofsymfony/user-bundle:2.0.*@dev
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
:
// app/AppKernel.php // ... class AppKernel extends Kernel { // ... public function registerBundles() { $bundles = array( // ..., new FOS\UserBundle\FOSUserBundle(), ); // ... } }
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:
$ app/console config:dump-reference AsseticBundle
or this:
$ app/console config:dump-reference assetic
The output will look like this:
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: []
# ...
At this point, check the README
file of your brand new bundle to see
what do to next.