Last updated February 22, 2016. Created on April 5, 2013.
Edited by Perignon, GoZ, TravisCarden, rivimey. Log in to edit this page.

There is a more up-to-date article on the phpstorm website.

This article adapted from the original article PhpStorm for Drupal by Angus Mak of Lullabot

Debugging Drupal modules and themes (or Drupal core itself) can be challenging without a good IDE. PhpStorm has earned its place as one of the primary IDE for almost any Drupal-related development. By default, PhpStorm is as Drupal friendly as most other IDEs. However, some of its default syntax and formatting settings conflict with the Drupal Coding Standards. Here are a few tips to make PhpStorm play even better with Drupal.

Contents of this Page

# Keymap

Although not related to Drupal, the Keymap is the first thing to change. By default, PhpStorm comes with keyboard shortcuts that can feel unnatural. Under Preferences, scroll down to select Keymap on the left, and select the keymap that suits your needs. Mac OS X 10.5+ feels the most intuitive to me. You can also further customize the keyboard shortcuts to each of the actions.


# Syntax and Formatting

Next, let's fix the code style. Drupal recommends less than 80 characters per line, and PhpStorm lets us set that as its default.


This gives you a nice solid line in the editor showing where the 80 character limit is. I leave the "Wrap when typing reaches right margin" setting unchecked; otherwise, PhpStorm will automatically insert line breaks when I hit 80 characters. Drupal's coding standards do allow more than 80 characters in some situations, so it's best not to require it.

# Syntax

Next, we'll work on PHP syntax. PhpStorm conveniently comes with a predefined style for Drupal that we can use as a starting point.

Drupal style

PhpStorm's "Tabs and Indents" settings should all be set to two characters to match Drupal's indentation standards.

On the "Spaces" tab the defaults are good.

On the "Wrapping and Braces tab", make sure these settings are set correctly:

  • Change Keep control statements in one line to be unchecked
  • Confirm Place braces in class declaration should be End of line
  • Confirm Place braces in function declaration should be End of line
  • Confirm Function declaration parameters should be Do not wrap
  • Confirm Function call arguments should be Do not wrap
  • Confirm force braces for if() statements should be Always
  • Confirm Else on new line for if() statements should be checked
  • In the function declaration parameters section, you must also check the "Keep ')' and '{' on one line" setting.

Wrapping and braces

  • Confirm Force braces for while() statements should be Always
  • Change 'While' on new line for do...while() statements to be checked
  • Change 'Catch' on new line for for try() statements to be checked
  • Confirm Chop down Array initializer if long should be checked
  • Confirm New line after '(' for Array initializer should be checked
  • Confirm Place ')' on new line for Array initializer should be checked

Wrapping and brances

Finally, on the "Other" tab, be sure that "Convert True/False to uppercase" and "Convert Null to Uppercase" are checked as well. Those changes should be all we need to match Drupal's PHP syntax. You might also want to set up syntax for other languages like HTML, JavaScript, CSS and any CSS preprocessors you may use.

# PHP CodeSniffer

Use PHP CodeSniffer to give extra warnings about Drupal coding standards violations. Follow the instructions to install PHP CodeSniffer and the Drupal coding standards definitions. Once you have phpcs ready, set up PhpStorm's Code Sniffer settings to point at /usr/bin/phpcs. Also, make sure PhpStorm is set up to use the PHP Code Sniffer for code inspection in its "Inspections" settings.


Now you should get warnings as reminders for keeping up the coding standards.


The Drupal coder sniffer settings need to be located in the PHP/Codesniffer/Standards folder located at /usr/local/pear/share/pear/PHP/CodeSniffer/Standards (location may be differ per environment).

More information on how to configure CodeSniffer in PHPStorm.

Mac users who are using homebrew to update their packages can use the homebrew-php brews available at

On windows enviroment you should use path <your_xampp_folder>/php/phpcs.bat instead of /usr/bin/phpcs (in PhpStorm settings PHP -> Code Sniffer)

# Tips and Tricks

If changing the font size is not something you often do, I would also recommend turning off the "Mouse wheel zoom" feature. I noticed a lot of accidental zooming in and out when using Magic Mouse on OSX. Even when the Mouse Wheel zoom is turned off, I can still use Pinch-to-Zoom on the trackpad when I need to. You can also set up your own keyboard shortcut under Keymap in Preferences.


# Debugging

One of the biggest advantages to using an IDE like PhpStorm is integration with a good PHP debugger. If you want to XDebug to examine Drupal's internals, see Lullabot's article about configuring Xdebug. It should give you everything you need to set up PhpStorm for serious debugging.

# File Types

To have PhpStorm style Drupal files like .module, .profile, etc as .php files, Under PhpStorm's Preferences, IDE Settings, select File Types. To the right under Recognized Files Types, select PHP files (PHP) and then click the + sign in the Registered Patterns section. If you have followed the above instructions, *.module will have already been added, but you will likely want to add *, *.install, *.profile (among others). Hit Apply and OK to apply your new settings and your files will now all be styled nicely per PhpStorms styles for PHP.

file types for php storm

# Namespaced classes

In .module files PhpStorm by default autocompletes class names to their fully qualified class name ie. namespace + class name. You should instead add a use statement and use only the shortname of the class. To do this, under Editor » Auto import check "Enable auto-import in file scope". The other checkbox is for the same behavior inside namespaced classes. .

# Arrays

PHPStorm can also handle array syntax in code formatting. In Drupal, we always add a comma at the end of a multiline array. Also, as of PHP 5.4, there is support for short array syntax. Drupal community is to slowly migrating to the short arrays. Short arrays are preferred, but not required. To set PHPStorm to always add the commas and to use short array syntax (optional), go to Settings->Editor->Code Style->Other(tab). The array settings are located at the bottom of the "Other" settings tab.

# Notes

Coding standards support built-in starting with version 7. See for a tutorial.

1_keymap.png122.35 KB
2_indent.png66.59 KB
4_drupal.png279.18 KB
6_spaces.png150.19 KB
7_wrapping_braces_0.png170.74 KB
8_wrapping_braces.png146.73 KB
11_inspection.jpg110.86 KB
12_highlight.png993.91 KB
13_editor.jpg154.17 KB
14_file_types.png106.04 KB
auto_import.png9.18 KB
Array settings for PHP Storm68.67 KB

Looking for support? Visit the forums, or join #drupal-support in IRC.


Elijah Lynn’s picture

The Future is Open!