Wednesday, February 25, 2015

How to install Symfony framework step by step for the first time

To a new user, installing Symfony framework seems somewhat different than other frameworks like CodeIgniter or other CMS like Wordpress and Drupal. While you can directly copy and paste the Symfony folder from Github, but the recommended way is to install through composer.


Symfony requires up-to date php version installed at your computer. It works with php5.4+ but recommended version is php5.5+ to support many new functionalities. You can check php version by using php -v at command line or call phpinfo() method in web server. Also, your web server and command line php versions might be different, if they are, you can add path to your php binaries to .bash_profile in Linux, Unix, or Mac computers and environment variables in windows machine. You will also need database server like mysql and preferably web server.


You can simply copy the symfony folder from github and run, like other simple frameworks and CMS. But the recommended method is installing through composer. It comes as a command line tool and we write different commands at command line to do required task. At first, command line tool might seem alian to new user, but actually, it is easier to use command line tool than other method. If you copy and paste github repository to your htdocs, you have set up the db and other credentials manually at app/config/parameters.yml file. If you can't find this file, rename parameters.yml.dist. With this, Acme demo is automatically installed and you have to unregister it and remove routes before you write production software.


Composer is installer and package manager of PHP. It is used by many frameworks and applications like Yii, Laravel, Symfony and others. It is very easy to efficiently install and manage dependencies through composer. Composer can be simply downloaded and installed in command line. More information about installing and running Composer can be found at Install composer beforehand proceed with next steps.

Installation with Composer

Navigate to wherever you like to install Symfony. Preferably in htdocs folder of your AMP stack. If you want to install Symfory in SchoolManagement/ folder then run following composer command

$ composer create-project symfony/framework-standard-edition SchoolManagement/

The above command tells composer to create project with code from vendor = symfony and product = framework-standard-edition into the local folder SchoolManagement. You can also install older or developmental version of symphony by specifying version number in single quotes, with ~ sign. For an example we install our standard edition of symfony framework with version = 2.6.

$ composer create-project symfony/framework-standard-edition SchoolManagement/ '~2.6'

Select Options for your application

Now it will ask you to select various options for your application. You have to answer these by typing in options or hitting enter if the default values is okay for you.

Would you like to install Acme demo bundle? [y/N] n

If this is your first time with symfony, you can chose to install Acme demo bundle. It is only demo files and not actually required. Chose N for not to install Acme demo bundle.

database_driver (pdo_mysql):
database_host (
database_port (null):
database_name (symfony):
database_user (root):
database_password (null):
mailer_transport (smtp):
mailer_host (
mailer_user (null):
mailer_password (null):
locale (en):
secret (ThisTokenIsNotSoSecretChangeIt):
debug_toolbar (true):
debug_redirects (false):
user_assetic_controller (true):

The options are self explanatory. You can just press enter to select the default option (in bracket). Pay special attention to database_name, database_user and database_password, write your db credentials to these variables. If you are using mamp, you might consider using
database_port (null): 8888
For secret, you should type any random string which is very hard to guess eg:
secret (ThisTokenIsNotSoSecretChangeIt): K3msp02M_kdl2mxldjza1qmCvD7xcvpoi43uXe
After this step, Symfony is installed.

Check if the installation is working

Change directory to the installation folder. For our case, write

$ cd SchoolManagement
Then check whether this installation is working properly.

$ php app/check.php
If there are any errors, it will show the message. If everything is right and you are ready to go, then it displays following message all in green

Your system is ready to run Symfony2 projects

Run your project

You can now run the Symfony2 project. You can test run it from your AMP stack or built in PHP web server.

Run from AMP stack

If you have AMP stack then point to following addres localhost in the browser. If you are hosting elsewhere, go to your webserver and following address in the web browser to access the Symfony project

One important thing that you should consider is you have to include web/app_dev.php after your host to run it properly. If you want to remove this, follow another manual How to remove web/app_dev.php or web/app.php in symfony project. or

Running from built-in php server

If you don't have webserver or like to access directly to this site, you can run following command

$ php app/console server:run
Server running on http:

You can access it in web browser by going to site


You will see symfony logo and debug bar, which signifies it is working properly. Symfony actually gives no route found exception if you haven't installed Acme Demo Bundle. But if you see symfony logo and debug bar, you are ready to go. You can start coding and defining routes. Now you have successfully installed Symfony2, ready to deploy. If you have installed Acme Demo Bundle, and want to remove this after initial testing, you can follow How to remove Acme Demo Bundle in Symfony project

No comments:

Post a Comment