Installation is easy! So let's get it behind us!

1) Install the Library via Composer

Download Composer and then run this command from inside your project.

composer require knpuniversity/guard-bundle:~0.1@dev

Use php composer.phar require knpuniversity/guard-bundle:~0.1@dev if you don't have Composer installed globally.

2) Enable the Bundle

Find your app/AppKernel.php file and enable the bundle:

39 lines app/AppKernel.php
... lines 1 - 5
class AppKernel extends Kernel
public function registerBundles()
$bundles = array(
... lines 11 - 19
new KnpU\GuardBundle\KnpUGuardBundle()
... lines 22 - 31
... lines 33 - 37

3) Build your first authenticator!

You're ready to build your authentication system!

A) Learn the fundamentals by building a login form

B) Create an API token authentication system

Leave a comment!

  • 2017-07-23 weaverryan

    Yo Pawel!

    Hmm. It looks like an issue with Selenium: This happens from time-to-time: as browsers make updates, Selenium needs to be updated to work with those browser changes. So, unfortunately, you will see issues like this occasionally - they're often fixed in the next version of Selenium. I would try a different browser for now, to see if you have better luck.


  • 2017-07-21 Paweł

    I put `selenium-server-standalone-3.4.0.jar` and `geckodriver` in my root project dir. I got error: `Exception thrown
    org.openqa.selenium.UnsupportedCommandException: mouseMoveTo`.
    I am using:
    Geckodriver v0.18.0
    Firefox 54
    Linux Mint 18.2

  • 2017-07-03 Victor Bocharsky

    Hey Evgeniy,

    Hm, are we talking about "BDD, Behat, Mink and other Wonderful Things" course? Probably if you did not have SQLite extension - you would have a huge error about it. I think the same is for permissions problem, so that's weird. Are you sure you do not see any errors in your terminal after "php app/console doctrine:database:create" command execution? What is your output? You should see something like:

    > ~/Downloads/behat/finish: $ app/console doctrine:database:create
    > Created database ~/Downloads/behat/finish/app/app.db for connection named default.

    Is it the same for you? Could you paste it here?

    Anyway, I just double checked it: Downloaded the course code, went to the finish/ directory. installed Composer dependencies and run "php app/console doctrine:database:create" - and it works for me fine.


  • 2017-06-30 Евгений Явгель

    Thanks for answer. But after command: php app/console doctrine:database:create no misstake but DB does not creating (( And "app/app.db" database file doesn"t create .... Why?

  • 2017-06-30 Victor Bocharsky

    Hey Евгений,

    That's not a full Symfony Standard Edition, just some kind of micro app based on Symfony components. This project doesn't have any parameters.yml and parameters.yml.dist files. For simplicity, all the configuration happens in app/config.yml - you can see:

    driver: pdo_sqlite
    path: %kernel.root_dir%/app.db

    So as you can see we use SQLite DB for this course, and after you run that commands from README file you will have "app/app.db" database file. So try to run those commands and make sure the app.db file is created. Of course, feel free to change driver to "pdo_mysql" if you want to use MySQL instead, but then you also need to set up its credentials under the "doctrine.dbal" key in config.yml.


  • 2017-06-30 Евгений Явгель

    Hi! I'm having trouble trying to load up DB. In README file after step 2 (composer install) I try to load DB by running stack of command: php app/console doctrine:database:create
    php app/console doctrine:schema:update --force
    php app/console doctrine:fixtures:load But in app/config I have no parameters,yml or parameters.yml.dist .... how can DB loading in this case ? README file says after running stack of commands above I must receive `app/app.db` file. But I havn"t app.db file. I cant run php app/console doctrine:database:create command Can you help me or explain what i miss?

  • 2017-05-15 weaverryan

    You already answered this for yourself in another thread, but I want to answer it here in case for others :). This tutorial is currently about an old bundle - in version 2.8 Guard was accepted into core (yay!) and now works a bit differently. You can find a screencast about this in our Symfony security tutorial:


  • 2017-05-15 Sergio Valije Guiadanes

    Hi everyone!

    I'm having this problem Viral had before, but I'm with this fancy Symfony 3.2.8 and I tried to follow the steps.

    Here is the output I got when I try to run my application

    InvalidConfigurationException in ArrayNode.php line 317:
    Unrecognized option "knpu_guard" under "security.firewalls.main"

    I'm missing something ?

    Thanks in advance!

  • 2017-03-27 Victor Bocharsky

    Hey UnkRec,

    No, you don't have - Guard component installed out-of-the-box, so just you can start using it. This tutorial is still current, but in some places we have notes if something was changed/renamed - just skip installation section if you're on Symfony 2.8 or higher.


  • 2017-03-26 UnkRec

    Do we have to install Guard via composer if using the latest version of Symfony 3 (to date)?
    How much of this " KnpUGuard: Symfony Authentication with a Smile Tutorial" is current?

  • 2016-12-17 weaverryan

    Thanks for sharing the link! And yea, I know what you mean - Behat docs are a bit light on some setup details... which is a shame, because it's SO rewarding to work with afterwards :). Happy you got there!

  • 2016-12-17 James D

    FYI, I found this article on Gecko webdrivers super handy:

    Also also, thanks so much for this course. I've been meaning to get round to learning Behat properly for months and I've always had set up problems. This is the first place I've found that explains how to get started properly.

  • 2016-12-09 weaverryan

    Sweet! So happy that worked - and thank you for the follow-up! Awesome!

  • 2016-12-07 James D

    Bingo! Worked a treat, thanks Ryan. I downloaded the Mac archive from, unzipped it, put the executable in my project root (though I guess it could have gone anywhere, and might more sensibly be kept somewhere like /usr/local/share or something.

    As you described, I added the path to the executable to my path, and now I can run tests with Selenium.

    Thanks again for your help!

  • 2016-12-05 weaverryan

    Hey James!

    Yea, Selenium is temporarily in a weird place right now as they've recently released their 3.0 version of the server, which has some differences with how the old one works. As I understand it, you need to also download the gecko-driver in order to use Firefox ( or the Chrome driver to use Chrome ( I *think* that you just need to make sure these are in your path (i.e. that you can just say chromedriver from the command line) - I don't *think* that you actually need to run them manually. I'm doing a lot of "think" because, while I have the new Selenium 3 server running on my machine, I had the chrome-driver installed a long time ago, so I'm not 100% positive what I might have done with my setup way back then.

    Anyways, let me know if downloading gecko-driver helps. Otherwise, we'll find the solution. I think we may need a note on this tutorial about the new setup steps with Selenium.

    Cheers and apologies for the inconvenience with Selenium!

  • 2016-12-04 James D

    Hey - I'm having a little bit of trouble with the Selenium part of this tutorial. I can run the scenario without Selenium, but when I try to do it using the @javascript option, Selenium opens up a Firefox window then just hangs. After a while I get a message saying:

    Could not open connection: Unable to connect to host on port 7055 after 45000 ms.

    ...followed by a load of console output from Firefox that I don't really understand.

    Any suggestions for what to do next would be much appreciated.

  • 2016-09-25 weaverryan

    Ah, great news!

  • 2016-09-23 Thierno Diop

    I notify the owner of the server about the problem and he fixed it buy setting varnish Thx a lot

  • 2016-09-23 weaverryan

    Yea, I agree that it sounds like a session-saving issue. But since you say that you *can* see session files created, and that they are created on each request, then it makes me wonder if Varnish is stripping the cookies so that each request (to Symfony) looks like a fresh request (i.e. one that has no cookie). I would remove Varnish, at least to test, and see if that fixes the problem.


  • 2016-09-22 Thierno Diop

    No i did that dump to verify if the session was working i asked to the owner of the server he tell me that he installed varnish and since i juste replaced a project who was on the server with mine i mean its the same domain i think that is the problem

  • 2016-09-22 Victor Bocharsky

    The PHPSESSID does not store in cookies for this domain. You can see it in Google Chrome Developer Tool. I think it's because you have a dump statement in DefaultController.php on line 17. Please, remove it and check again.

  • 2016-09-22 Thierno Diop

    My hostname is so i think thats not the problem

  • 2016-09-22 Victor Bocharsky

    One possible cause for this is having a host name without a domain part (.com, .org, etc.), e.g. http://example/ instead of

  • 2016-09-22 Thierno Diop

    Thx for your response
    Session are saved in the folder var/sessions but the problem is that for every request it create one file in the session folder

  • 2016-09-22 Victor Bocharsky

    Hey Thierno,

    You should configure session properly - most likely session can't be stored on your server. Where do you store session? If it stores in files - look at save_path option and ensure you setup permissions for it correctly on the server. Let me know if it helps.


  • 2016-09-21 Thierno Diop

    Hi Ryan i have a probleme with the guard authentication I use symfony 3.1 in my project the guard authentication work fine in my local machine but when i deploy to the server if the authentication succed i am redirecting to the home page but i loose the authentication and become anonymous again.
    I set a session variable to show it in another page but it turn that the variable was deleted .
    So i think that the session is deleted every request but i dont know why.
    Really need help Thx

  • 2016-07-25 Victor Bocharsky

    Hey ciudadano82 ,

    You don't have to install GuardBundle for Symfony 3.1 because Guard Component provides with Symfony out of the box since Symfony 2.8, so just start using it without installation! :)

    Check this blog post page for more information: .


  • 2016-07-21 ciudadano82

    Hi! I'm having trouble trying to download the guardBundle with composer, i've installed symfony 3.1.2 (currently the last version available), but i get the following error:
    Your requirements could not be resolved to an installable set of packages.

    Problem 1
    - Conclusion: remove symfony/symfony v3.1.2
    - Conclusion: don't install symfony/symfony v3.1.2
    - don't install symfony/security-bundle v2.8.8|don't install symfony/symfony v3.1.2
    - Installation request for symfony/symfony == -> satisfiable by symfony/symfony[v3.1.2].
    - Installation request for knpuniversity/guard-bundle ~0.1@dev -> satisfiable by knpuniversity/guard-bundle[0.2, 0.3, v0.1].

    Any help, please?

  • 2016-06-28 Viral Champanery

    yes, right .. that was the one of the concern about this. to update the version . i just tring to do the same as i got document in following link

    In above link it shows in symfony 2.3 so that i was trying to do that .... thats fine..thanks to supporting .... its very to chat with you.. .. keep in contact ...

  • 2016-06-28 Victor Bocharsky

    Hm, I think you need to update your Symfony application first, at least to the ^2.6 as we can see from dependencies, but it would be better upgrade to the 2.7 as this is a LTS (Long Term Support) version. Looks like this bundle can't be correctly installed on Symfony 2.3.

  • 2016-06-28 Viral Champanery

    sorry bro, i have tried in that also but it will give the same error ... may be the reason my symfony 2.3.* version .. but i am not sure about it

  • 2016-06-28 Victor Bocharsky

    That's because your symfony/security-bundle has unsatisfiable version. Could you try to update it to "symfony/security-bundle": "^2.6" in your composer.json file?

  • 2016-06-28 Viral Champanery

    When i put this " "require" : { "knpuniversity/guard-bundle": "0.1" " in my composer.jsno file and try to composer update following error shows :

    Your requirements could not be resolved to an installable set of packages.

    Problem 1

    - Installation request for knpuniversity/guard-bundle 0.1 -> satisfiable by knpuniversity/guard-bundle[v0.1].

    - Conclusion: remove symfony/symfony v2.3.23

    - knpuniversity/guard-bundle v0.1 requires symfony/security-bundle ~2.6 -> satisfiable by symfony/security-bundle[v2.6.0, v2.6.1, v2.6.10, v2.6.11, v2.6.12, v2.6.13, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6, v2.6.7, v2.6.8, v2.6.9, v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.13, v2.7.14, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5, v2.8.6, v2.8.7].

    - don't install symfony/security-bundle v2.6.0|don't install symfony/symfony v2.3.23

    - don't install symfony/security-bundle v2.6.1|don't install symfony/symfony v2.3.23

  • 2016-06-28 Victor Bocharsky

    Hm, if you already installed guard library - that's not so bad. What error do you have during the GuardBundle installation?

  • 2016-06-28 Viral Champanery

    Hi victor,

    Thanks for giving me valuable time ,
    I have the my code in 2.3.23 symfony version and it allows me to add only guard but not guardBundle .so can you help me out with this. that i can make user login, changes password. functionality useing guardBundle in current version .. Is it possible to have with Fos.use bundle as well .. both in a one system ....

  • 2016-06-28 Victor Bocharsky

    Hey, Viral!

    There's the KnpUGuardBundle which you need to install first, because out-of-the-box Guard component available since Symfony ^2.8. only. But keep in mind that some dependencies should be updated to "^2.6". Check composer.json file of KnpUGuardBundle bundle to get more information about versions of dependencies.


  • 2016-06-28 Viral Champanery

    Hi, i have my application in symfony 2.3 so can i integrate it with this . because when i put composer update i got error like this " Unrecognized options "knpu_guard" under "security.firewalls.main" " in my security.yml it is like " knpu_guard:
    - app.form_login_authenticator "

  • 2016-02-15 Shaun

    Setting up the DB after downloading the course code was quite tricky, solved by trial and error, and really needs to be documented. From within ../start/
    1) php app/console doctrine:database:create
    2) php app/console doctrine:schema:update --force
    3) php app/console doctrine:fixtures:load

    Hopefully Ryan can review the steps above and check whether that's the best approach.

    (I just finished the Drupal 8 series by the way, and totally loved it. I just had to say that).

  • 2016-02-15 Daniel

    Thanks it worked, I all set with symphony 3 as well. Cheers!

  • 2016-02-11 weaverryan

    Hey Daniel!

    I have not totally set it up yet on Symfony 3, but I know at least that behat/mink is not compatible with Symfony 3 yet. Well, actually, it IS compatible - on its master branch, but there has not (yet) been a release with these compatibility changes. So, at the very least, you'll need to require behat/mink at the version dev-master. For Behat, you will need version 3.1 their of *their* library, which is not released fully yet. Try using ^3.1@dev in composer.json - or dev-master, that should do it.

    Some bundles/libraries have been slow to tag releases of their Symfony-3 compatible versions. It's made using some libs with Symfony 3 a pain. It should get better :).


  • 2016-02-10 Daniel

    Hi Ryan! What about having this setup for BDD in symfony3? Have you tried it? I got a myriad of composer conflicts, too long to be put here

  • 2015-12-15 tomhv

    Awesome, thanks! That makes a lot of sense.

  • 2015-12-15 weaverryan

    This is a *great* question... so I talked to some of the guys at KnpLabs about it. I'll make a few points:

    1) The first important thing is communication. If *you* know that you will ultimately need features and scenarios, then when planning with your client, you should sit down and communicate (ask questions, etc) in a way that will ultimately allow you to easily write those features/scenarios. Using BDD clarifies your planning process, and you can use that to help your client plan.

    2) Regardless of whether you ultimately write the features/scenario or your client does (see my next point), you should validate the features/scenarios with your client. That will get them invested in the Gherkin process and avoid those ugly miscommunications about features :).

    3) I don't think it will always work, but you may be able to get your client invested enough in Gherkin that *they* start to write the scenarios. During our discussion about this, we basically agreed that you will always need to "translate" their scenarios a little bit (Gherkin is natural language, but it still has structure). Really, even my point (1) above was about translating your conversation with them into written scenarios. There will always be a translation step, but the smaller you can make that translation, the less translation "cost" you will have (time to translate, mistakes in not translating what they mean perfectly, etc).

    Thanks to these guys for our conversation about your cool question: and


  • 2015-12-15 tomhv

    Where does Behat fit into the requirements-gathering process? Do you sit and write the features with the client?

  • 2015-11-13 AJ


  • 2015-11-13 weaverryan

    Got it fixed now thanks to your comment!

  • 2015-11-13 AJ

    This video is different from the script. Was that intentional?