JetBrains PhpStorm, is, surprisingly, an incredible IDE, and works extremely well for Drupal development. We took some time to go through all the various custom settings and get things set up to obey Drupal's coding standards, so we thought we'd share.
First of all, JetBrains's PhpStorm IDE is payware. Second of all, I lost so many hours of my life to frustrations with Eclipse that I was quite happy to fork out the relatively low cost once I'd given it a trial. This is not a post to discuss IDEs or the merits of one platform above another, but suffice is to say that PhpStorm, against all odds, is now my preferred IDE on Linux. YMMV.
I'm going to assume you've set it up, you're using Ubuntu (mostly it won't matter what OS you're on for this blog post) and you're using the Sun version of Java. You are using the Sun version, right?!
Basic settings
Head into the settings from File > Settings.
First, go to Editor and in the Other section, set Strip trailing spaces on Save to All. Also, turn on Ensure blank line before end of file on Save.
Now, expand Editor and head to Editor > Apperance. Turn on Show line numbers unless you love not knowing what line you're on.
Head to Code Style > PHP and make sure Global settings is in use at the top, otherwise you'll have to set these options for each project you work on. Change Tab size to 2 (usually it defaults to 4) and also change Indent and Continuation indent to 2 too.
The rest of the settings in Code style > PHP are actually very sensible, and the only other thing you might want to consider is in the Other tab, turning on Indent code in PHP tags which is not a Drupal standards issue, but I do prefer code that way.
Next, check that under File encodings, the IDE encoding is on UTF-8. You will also want to make sure that under Code Style > General you have set Line separator (for new files) to Unix (this is especially important if you're using Windows) and set Right margin (columns) to 80.
Again, under Code Style > General, set Tab size, Indent, and Continuation indent to 2. Head into each section of Code Style, such as CSS, HTML, etc and make sure all indents are set to 2 on everything.
File types
Drupal has some unusual file extensions and you will need to configure these under PhpStorm to be able to edit them. Head to File Types, click PHP files in the upper pane, and add *.install, *.module, *.profile, *.test, and *.theme.
Inspections
Inspections are a really powerful way of letting you know you're writing crap code, and will often catch things that most humans will miss. You absolutely don't want inspections to be showing you any false positives if possible, since this will create a 'boy who cried wolf' effect where you won't notice things that are genuinely wrong because you're so accustomed to looking at 'wrong' inspections.
Head to Inspections. For me, it's best to set up the global inspections and use them for all projects, so that's what we'll cover here, although it's also possible to have different inspections for different projects. First, choose Default in the drop-down at the top left (not Project default) and click Share profile.
Turn off the Spelling inspection, unless you really enjoy your IDE telling you that function names are not valid English words! Alternatively you can open it up, choose the Typo inspection, and configure it to only spell check in comments, but I prefer to just disable it and spell things properly myself.
Open up PHP > PHPDoc. You will probably want to turn off Missing @return statement and PHPDoc comment matches function/method signature, and turn on Missing PHPDoc comment. The reason is that under Drupal standards, you don't need to fully document hook implementations. If you leave on those inspections, you will get a lot of errors. On the other hand, you should never have any function that has no documentation for it, even if it's just to say it's implementing a hook, so turning on that inspection will help you out.
Head to PHP > Undefined and turn off undefined variable and undefined field. The reason is that, for whatever reason, it was decided that Drupal should use stdClass objects as data stores, rather than arrays, so you end up with things like $node->title, which, since $node is an object of type stdClass, and not a proper object, generates an undefined field warning. You might need to turn off more of these, so try it out and see how it goes.
Project-specific
Once you've actually opened up a project (which should be as simple as opening a directory, as PhpStorm can detect things like whether it's under git source control), you will want to set up some include paths. This only applies if, like us, you run Drupal multi-site, and your project is just the site itself, rather than the entire Drupal installation. If you added the entire Drupal installation as your project, you needn't worry about this, as it's taken care of for you.
In the project panel, right-click where it says External Libraries and choose Configure Include Paths. Now, add 3 new include paths. These will be /path/to/drupal6/includes, /path/to/drupal6/modules, and /path/to/drupal6/sites/all/modules. This will allow PhpStorm to know about all Drupal's internal functions and any functions inside modules like views where these are stored outside of the current project.
Enjoy
That should be it. You're now good to go develop a Drupal site, module, theme or whatever it is you're doing using PhpStorm. If I did miss anything off this list, do let me know in the comments and I can add it in.
Quick update: Thanks to Timon Royer for letting us know about his PhpStorm and Drupal video which runs you through some of the ways PhpStorm makes your life as a Drupal developer easier. He seems to be a mac user, but we can overlook that, right? ;)
Comments
It would be great if this were added to the documentation on d.o. Check out http://drupal.org/node/147789 and add a child page called Configuring PHPStorm.
PhpStorm does look interesting - I also had given up on Eclipse a long time ago and was working with Vim. Thanks for showing the settings!
If you like VIm, try the IdeaVIM plugin on PHPStorm. I was sold with PHPStorm out of the box, but being able to use VIm keystrokes inside has kept it 'Storm as my #1 tool.
The plugin's a little buggy -- occasionally, eg, undo undoes a ton more than it oughta -- but overall it's a great plus in the pro-PHPStorm column.
I created a project on Github containing snippets (aka Live Templates) of all core hooks (D7) for PHP Storm. Check it out and contribute ! https://github.com/DjebbZ/Drupal-PHPStorm-Live-Templates
PhpStorm is definitely my IDE of choice for Drupal development and version 3 just made me even more sure.
If you would like to work in PhpStorm with a nice color scheme, I can recommend Ethan Schoonover's Solarized profiles. You can find them here:
http://ethanschoonover.com/solarized
(Grab the IntelliJ IDEA one, it will work the same in PhpStorm.)
Will check out DjebbZ's snippets :)
The Strip trailing whitespace should be set to "Modified Lines" if you are preparing a core feature patch. This prevents spurious changed lines.
Alternatively, file a whitespace patch first :).
I would not turn off undefined variable inspection, it's very helpful.
Also, there's no need to adhere strictly to the substandard Drupal code standards for in-house projects. Eg: I do include param and return types in PHPdoc; both the additional documentation and the automated checking by PHPstorm are very handy.
Nice article, but I have a question.
What's wrong with eclipse?
This is probably a silly question, and something I'm doing wrong.
When I create a new project from a git repo on a remote server, everything sets up correctly. However, in the Project panel (directory navigation), I can only see files, and not folders (have to use the navigation bar which is annoying). How can I get it to show the whole directory structure?
Also, I cloned a full drupal installation, and it's telling me that all of Drupal's built-in functions can't be found. I also tried adding the folders mentioned in the include path, but still nothing.
This is indeed bizarre. I've definitely included all the correct extensions, am using the root at the project, and this is what I get:
http://cl.ly/0i1C2b2a083F0A0y2G2f
Seems like a nice IDE, but I can't even get started!
Thanks for the help.
Thats a good thought. Changed to 777 and same problem. Interestingly enough, a different repo on the same remote server worked fine. I re-initialized the problem repo and now it's working well. No idea what the issue could have been!
Anyway, thanks for the writeup. Been searching for an IDE I actually like, maybe this one will be it.
PHPStorm is pretty sluggish and locks up often on OSX. Anyone know why?
I did not experience this on OS X. If you want, post a support request on the phpstorm website (http://www.jetbrains.com/support/phpstorm/index.html). Do not forget to tell them about your system and project setup.
Make sure that you selected the correct scenario when you created a project. It is very important to not work on network-mounted drives without a local backing project with autosync.
In such case you should select the option "Web server is on remote host, files are accessible via network share or mounted drive." or you won't have a great experience.
I've created a video that shows how to use PhpStorm with Drupal. The tutorial shows important PhpStorm features and how to use them in Drupal projects. Learn how to use the most common hotkeys for navigating and editing your code. http://youtu.be/J786StrcGmc?hd=1
Thanks for this. IDEA/PhpStorm is one of the very few commercial web development tools I'm willing to pay for.
Great article! I would like to add that (at least in PHPStorm 3.x) according to the 'Undefined field' inspection's description:
"Check is not performed on objects of type "stdClass" or derived."
So no need to turn that off, right?
Lovin' PHPStorm ... hands down, the best web IDE for me. Eclipse, Aptana/Titanium, Netbeans, etc. ... they all trail. Thanks for the config tips.
Some guidance appears to be out of sync for PhpStorm 4.x; could have some folks scratching heads, e.g. no Global settings in Code Style > PHP, just immutable Default and Project. They also now have a Drupal coding style option that can be set. I have chosen to use the Drupal scheme and make any mods to that; then I simply select it when I create a Drupal project.
ITIL is most dеfinitеly beсoming much more vitаl in
todаy's IT companies around the globe. I understand that, in my encounter, it does not constantly go 100 % to plan - yet thats the reason why Itil is just a framework I guess.
Review my site :: www.realworlditil.com
Thank you for documenting these steps - nice to know where to start setting this up! I was hoping you'd have more tips when it comes to a Drupal multi-site setup?
If I make the Drupal root the PHPStorm project -> then I can debug modules in in sites/default/modules and in sites/all/modules, but not in eg. project.ca/modules.
If I make the project.ca the PHPStorm project and include as external libraries: drupal7_root/includes, drupal7_root/modules and drupal7_root/sites/all/modules - then I'm getting an error message that "Remote file path '/drupal7_root/index.php" is not mapped to any file in project.
I'm also going to need to debug modules that interacting with CiviCRM / not sure yet what that will look like - basically there will be w more index.php files in addition to the drupal7_root/index.php one.
Thanks,
I'm wondering if perhaps my ln -s are causing issues [I'm basically ln -s sites/project.ca sites/project.local so that as far as Drupal is concerned everything is still in the same place - and I can browse to the site by using http://project.local
So if I try this for a sites/default:
SCENARIO A.
1. Create New Project from Existing Files
2. Web server installed locally, source files are located under its document root.
3. Choose a directory to create the project in:
/Applications/MAMP/htdocs/Linode/domains/drupal-7.0/sites/default
[yes I'm on a Mac for local development :-) shouldn't be the issue though - and it's nice to have PhotoShop/AI handy]
4. Add new local server:
Name: d7.semper-it.local
Web server root URL: http://d7.semper-it.local
5. Web path for project root
empty I think (?) project URL should be: http://d7.semper-it.local
6. Finish - getting a green checkmark from PHPStorm in my dock - so far so good.
7. External libaries: adding (to start with):
+ /Applications/MAMP/htdocs/Linode/domains/drupal-7.0/sites/all/modules
+ /Applications/MAMP/htdocs/Linode/domains/drupal-7.0/modules
+ /Applications/MAMP/htdocs/Linode/domains/drupal-7.0/includes
Ok
8. Open file in /project.local/modules/ (subscriptions.module in this case)
Looks fine file loads - color scheme is fine - structure window looks fine.
9. Add debug mark in subscriptions_init() and start listening (phone icon -> green).
10. Add cookie in browser when on http://project.local (check - yep it's there) - and click on logo to go to http://d7.semper-it.local
14. Incoming Connection From Xdebug
- Server name: d7.semper-it.local
- Server port: 80
- request uri: /
- File path on server:
/Applications/MAMP/htdocs/Linode/domains/drupal-7.0/index.php
Select a project or file to debug (I have civicrm in /sites/all) so my choices are:
/sites/all/modules/civicrm/install.index.php
/sites/all/modules/civicrm/packaged/dompdf/index.php
I don't have a choice for a Drupal index.php
Accept
Nothing happens [no more error messages but nothing happens]
NEXT:
project in drupal-7.0
SCENARIO B
0. rm -r .idea that exists.
1. Create New Project from Existing Files
2. Web server installed locally, source files are located under its document root.
3. Choose a directory to create the project in:
/Applications/MAMP/htdocs/Linode/domains/drupal-7.0
4. Use existing server:
Name: d7.semper-it.local
URL: http://d7.semper-it.local
5. Web path for project root
empty I think (?) project URL should be: http://d7.semper-it.local
6. Finish - getting a green checkmark from PHPStorm in my dock - so far so good.
7. External libaries: should be ok we're now in drupal root.
8. Open file in sites/default/modules/ (subscriptions.module in this case)
Looks fine file loads - color scheme is fine - structure window looks fine.
9. Add debug mark in subscriptions_init() and start listening (phone icon -> green).
10. Add cookie in browser when on http://project.local (check - yep it's there) - and click on logo to go to http://d7.semper-it.local
14. Incoming Connection From Xdebug
- Server name: d7.semper-it.local
- Server port: 80
- request uri: /
- File path on server:
/Applications/MAMP/htdocs/Linode/domains/drupal-7.0/index.php
Select a project or file to debug (I have civicrm in /sites/all) so my choices are:
/Applications/MAMP/htdocs/Linode/domains/drupal-7.0/index.php (this is NEW)
/sites/all/modules/civicrm/install.index.php
/sites/all/modules/civicrm/packaged/dompdf/index.php
I do have a choice for a Drupal index.php - select it.
Accept
AND we're debugging - all is well.
If you can find an AHA moment here - then please let me know - and if you give me your address - some maple syrup may just find it's way across the ocean!
Tnx for this article. Like lot of people, I'm searching for a IDE that works. I start looking at PhpStorm.
I've one question about the .idea folder. Is there a way to get this folder outside of the Drupal-folder , to keep Drupal clean ?
Tnx Chris.
There's another thing that I don't really get. While creating a new Drupal site, you'll create the Drupal-site-folder and import it into PhpStorm. But, do you "open a directory" or create a "new project from existing Files" ?
It seems to me that this IDE works ... :) Still 29 days to go for free.
Great! Post, thanks!
Developer can also configure Drush commands (as dl, en, etc) in external tools section.
This was helpful so thank you! Maybe I'm using a newer version or something but there isn't an editor -> other section. Also, I copied my site from the server to my PC into PHPSorm and the 3 paths to add to the External Libraries didn't work. I am going to see if I can get things working anyways.
Thanks for writing this up! I am using IntelliJ IDEA as my PHP IDE of choice, but since PHPStorm shares most code with it, all settings were where you said they were. Looking forward to try this configuration and improve my module development.
Thanks for taking the time to write these great pointers on setting up PhpStorm for Drupal. I am a huge fan of this IDE and your tips really help working with Drupal files.
Thanks for sharing. I set it all up correct now in PHPStorm for drupal :-)










