Create a Symfony 2 project with PhpStorm 8 or 9

Written by Martijn Braam on 2014-06-30

Edit: Updated for Symfony 2.7 Edit: Updated for PhpStorm 9 EAP

This tutorial has been written for the early access program version of PhpStorm 8 (PhpStorm PS-138.826 to be exact) and Symfony 2.7.x.

  1. On the PhpStorm welcome screen select the Create New Project option.
  2. Fill in the Project name and Location as usual.
  3. Set the Project type to Composer Project
  4. If you've already download composer.phar somewhere set the the Use existing composer.phar option, otherwise select Download composer.phar from getcomposer.org
  5. in the package section search for symfony/framework-standard-edition
  6. select the latest release version in the version dropdown. This is the v2.7.5 version at the time of writing. You can also use v2.8.x-dev to get the latest development release
  7. Press ok and wait a while

Now you have a basic empty symfony 2.7 project in your project root. For further integration between PhpStorm and Symfony some plugins should be installed.

  1. Go to File -> Settings -> Plugins (or PhpStorm -> Preferences -> Plugins if you're on a mac)
  2. Install Symfony2 Plugin, Twig Support and YAML through the "Browse repositories..." menu
  3. If you use the PhpStorm 9 EAP version you also need the "Framework MVC Structure Support" plugin from the "Install JetBrains plugin" menu
  4. Restart PhpStorm
  5. Go to File -> Settings -> Symfony2 Plugin
  6. Check Enable Plugin for this Project
  7. Now go to Directories under Project Settings and exclude app/cache and app/logs. This helps with performance problems in PhpStorm
  8. Still in the settings page, go to PHP -> Framework Integration
  9. Check Enable framework integration and change Autodetect to Symfony2
  10. Browse to web in the file tree and set Element to web root directory
  11. Set the element for vendor to vendor
  12. Set app to application configuration directory
  13. Set src to project code directory
  14. Restart PhpStorm (Its starting to look like firefox)
  15. Click on View -> Tool Windows -> Framework

Integrating the Symfony Console

It is also possible to integrate the symfony console with PhpStorm (<project root>/app/console). This enables help and completion for the symfony commands (build in and your own) and saves you from typing php app/console do:something every time.

  1. Go to your project settings/preferences -> Tools -> Command Line Tool Support
  2. Click the green plus button and set the "Choose tool" menu to "Symfony" and make sure the visibility is set to "project" (since the app/console script is specific for one symfony installation)
  3. Then for "Path to Symfony" choose /app/console in the filebrowser
  4. Make sure a valid PHP executable is chosen in the "Path to PHP executable" field.
  5. Press ok a few times to save everything. Now you have console integration.

To use this integration go in the main menubar to Tools -> Run Command..., A new tool window should appear. The alias for php app/console is now s so you can type s doctrine:create:database for example to run a command.

Creating a bundle

Now your development environment is set up for the Symfony 2.7 project. The last thing to do to start is create a new bundle in Symfony for your project.

  1. Open a terminal in phpstorm (alt+F12 on linux, double press shift to search for "terminal" in phpstorm)
  2. Run php app/console generate:bundle --namespace=company/project --format=yml (don't forget to replace company/project)