Monday, November 16, 2015

Basic User Management in Symfony2 with FOSUserBundle

Symfony has a very powerful authentication and authorization system, which can cater to a lot of our needs out of the box. FOSUserBundle is a library built on top of Symfony’s security system, which provides functionality such as registration, login, password resets, etc. It has built in support for MongoDB, as well as ORMs such as Doctrine, Propel, etc.

Users networked graphic

We will use Homestead Improved for our demo.

Add a new site in the Homestead.yml file.

sites:
    - map: symfonylogin.app
      to: /home/vagrant/Code/SymfonyLogin/web
      type: symfony
databases:
    - symfony

This will set up a new site in the VM that points to the web folder of the Symfony application. When type: symfony is specified, it will pick an Nginx configuration that is specifically created for Symfony applications.

We should also add 192.168.10.10 symfonylogin.app into the main operating system’s /etc/hosts file. Now we can boot the VM with vagrant up.

Before we begin, let’s quickly set up the Symfony application using Symfony’s installer, a command line tool for installing Symfony projects. To install the installer, enter the VM using vagrant ssh and run the following commands.

curl -LsS http://ift.tt/1vcjPAo > symfony
sudo mv symfony /usr/local/bin/symfony
chmod a+x /usr/local/bin/symfony

The first command downloads the installer from the Symfony website to the current directory. Then we move it to the bin directory and make it executable.

Now let’s create a Symfony application inside the VM.

cd Code
symfony new SymfonyLogin

This will create a Symfony skeleton application and install all the dependencies from Packagist. Once it’s finished, go to the app/config folder and update parameters.yml with the database and email configuration.

Continue reading %Basic User Management in Symfony2 with FOSUserBundle%


by Shameer C via SitePoint

No comments:

Post a Comment