Create a Symfony 2 project with PhpStorm 8 or 9
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.
- On the PhpStorm welcome screen select the Create New Project option.
- Fill in the Project name and Location as usual.
- Set the Project type to Composer Project
- If you've already download composer.phar somewhere set the the Use existing composer.phar option, otherwise select Download composer.phar from getcomposer.org
- in the package section search for symfony/framework-standard-edition
- 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
- 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.
- Go to File -> Settings -> Plugins (or PhpStorm -> Preferences -> Plugins if you're on a mac)
- Install Symfony2 Plugin, Twig Support and YAML through the "Browse repositories..." menu
- If you use the PhpStorm 9 EAP version you also need the "Framework MVC Structure Support" plugin from the "Install JetBrains plugin" menu
- Restart PhpStorm
- Go to File -> Settings -> Symfony2 Plugin
- Check Enable Plugin for this Project
- Now go to Directories under Project Settings and exclude app/cache and app/logs. This helps with performance problems in PhpStorm
- Still in the settings page, go to PHP -> Framework Integration
- Check Enable framework integration and change Autodetect to Symfony2
- Browse to web in the file tree and set Element to web root directory
- Set the element for vendor to vendor
- Set app to application configuration directory
- Set src to project code directory
- Restart PhpStorm (Its starting to look like firefox)
- 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.
- Go to your project settings/preferences -> Tools -> Command Line Tool Support
- 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)
- Then for "Path to Symfony" choose
/app/console in the filebrowser
- Make sure a valid PHP executable is chosen in the "Path to PHP executable" field.
- 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.
- Open a terminal in phpstorm (alt+F12 on linux, double press shift to search for "terminal" in phpstorm)
php app/console generate:bundle --namespace=company/project --format=yml(don't forget to replace company/project)