Understanding Directory Structure of Symfony 2

Symfony 2 is a PHP framework. When you download it, if noticed, Symfony 2 has a directory structure. By default there are 5 directories like app, bin, src,vendor, web. If you had developed any kind of application with Symfony 2 then you might have followed something like put your source code in src, put all static assets in web, write config files in app etc. Again this directory structure is configurable, that means you can customize it according to your project needs. Even though the directory names are self-explanatory, let’s have a deeper look of this structure.

By default Symfony consists of following directories,

  • app/: The application configuration
  • src/: The project’s PHP code
  • vendor/: The third-party dependencies
  • web/: The web root directory


‘app’ directory in Symfony 2 holds the application configuration. You can find all configuration related stuff in ‘app/config’ folder. If you need to configure your database or Swiftmailer then you will need to change parameters/settings from here. Apart from that this directory holds the ‘cache’. While writing code in Symfony 2 you will be working with lots of files ranging from xml, yml to php, twig, html etc. Controllers will be written in some file, routes will be defined in some another files, views will be written in some other file and so on. So while serving request Symfony has to read all these necessary files. Since the count of files is too high, to achieve great performance Symfony 2 has inbuilt caching. And this cached data will be stored in ‘cache’ directory. Again there is a ‘log’ directory which has debugging related data, especially useful in development.

Apart from all these directories, the ‘app’ directory also holds, ‘AppKernel.php’. This is nothing but heart of Symfony 2 in other words this file is the entry point for any Symfony 2 project.


By default this folder has some security check functions. We can use this directory same as ‘vendor’ directory.


Again the most important directory in the Symfony 2. This directory will be holding source code of your app. You have to create controllers, views, routes in this directory only. All of your PHP and template related files will be residing in this directory. Symfony 2 follows ‘bundle system’. There is good explanation of this bundling system in Symfony 2 docs, you can read it here.


‘vendor’ directory holds all third-party dependencies. To install and manage dependencies you will need ‘Composer’. Most commonly you will be using ‘doctrine’ for database related things and ‘twig’ for template/views related things.


‘web’ directory is web root of your Symfony 2 project and will be used to store static data like images, css of your app. This directory has two important files ‘app.php’ and ‘app_dev.php’. ‘app.php’ will be used in production environment while ‘app_dev.php’ will be used in development environment. In Symfony 2 you have to pass all requests to these files to boot up Symfony and get your work done. This files will internally load whole Symfony for you, will look up for routes, will execute associated controllers, will generate view and will display your results. Apart from that the ‘web’ directory has some general purpose files like robots.txt, favicon and apple icon.

In root directory, you will find a file named ‘composer.json’. This file used to hold the composer configuration. You have to edit this file to add, modify or remove third-party dependencies.

Apart from that there are some read me files in root directory. If you want, you can read them else just forget about them.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.