How to configure "Directories" when using a Symfony project in PhpStorm

Solution 1:

The vendor folder is not a resource root. A resource root is a folder where resources such as images and scripts will be served from by the web server.

In your case the only folder that should be marked as a resource root is probably the web folder, but ironically, is almost the only one you haven't selected as a resource root. Marking web as the resource root means that the absolute URLs /css/foo.css and /images/foo.jpg could be valid resources served by the web server; you probably want to remove all other folders from resource roots.

It is correct to exclude the vendor folder because it is not part of your first-party project code. In order for code completion to work for third-party code you must add the vendor folder as an external library. This can be done by navigating to Languages & Frameworks > PHP in the options and specifying the vendor folder as an include path.

Solution 2:

After having used advices from Quolonel Questions's answer, here is a summary of my configuration for Symfony2 (see Symfony3 at the end of this answer):

For auto-completion, use the vendor/ directory in Include path:

enter image description here

In order to avoid irrelevant results when searching in the project, the following directories have to be ignored:

.idea               [excluded]
app/
  ├ cache           [excluded]
  └ logs            [excluded]
vendor/             [excluded]

enter image description here

Here is my full configuration:

.idea               [excluded]
app/
  ├ cache           [excluded]
  └ logs            [excluded]
src/                [source]
  └ AppBundle/
    └ */Tests/      [test source folders]
vendor/             [excluded]
web/                [resources root]

Test Source Folders are optional, if they are defined the will appear in the toolbar:

enter image description here


With the default configuration for Symfony3, the directories are slightly different:

.idea               [excluded]
src/                [source]
tests/              [test source folders]
var/
  ├ cache           [excluded]
  └ logs            [excluded]
vendor/             [excluded]
web/                [resources root]

Update: after updating my dependencies with composer update, PhpStorm perform searches in the vendor/ directory, even if these directories are ignored. The solution is to remove all the vendor/* directories from Include path and keep only vendor/ directory, as on the first screenshot.

I'll have to test if marking all the vendor/* directories as ignored can work and avoid to repeat this after each time composer update is used.

Solution 3:

Another option which is easier than manually excluding vendor and then including it again in php settings, is to tell PhpStorm about composer.json and composer.phar in the composer settings as showin in this question.