Menu
Skip to end of metadataGo to start of metadata
PHPStorm will begin indexing the files and detect that it is Drupal project. It will prompt you to enable the Drupal coding standards, indicate which directory contains the installation path, and if you want to set PHP include paths. All of that is optional but recommended, especially if you want to use this VM for long term development. Multistep popup form in Drupal 9.9. Configuration management in Drupal. Active, Sync configuration, transfer configurations from DEV to LIVE.
I'm using the PhpStorm 7.1 release and drupal 7.24. I created a module. But there is a problem using xdebug.phpinfo tells: Version 2.2.3 IDE Key XDEBUGECLIPSE First I set a breakpoint at the f. Drupal 9 does not represent a great milestone in the traditional sense. It does, but not one comparable in scale to the release of Drupal 8.0 when the entire world cheered and the stock markets rallied. Rather, Drupal 9 represents proof that some decisions were made wisely when the time came to change the release approach Drupal was accustomed to.
Overview
PhpStorm: A Drupal-friendly IDE
- Easy to configure, especially when using Acquia Dev Desktop + XDebug
- Download: http://www.jetbrains.com/phpstorm/
- 30-day trial available
- Similar to other JetBrains IDEs, e.g., RubyMine, IntelliJ: http://www.jetbrains.com/products.html
Configuration
- Key Map: Mac OSX 10.5+
- IDE theme: Darcula
- Editor color/fonts: Darcula
- Enable command line
Drupal Code Style
- General: Code Style: 80 right margin; Tab size/indent/continuation: 2
- PHP: Set from Predefined Style > Drupal; Tabs: All 2; Wrapping and Braces: check 'catch on new line' for 'try'
XDebug with Acquia Dev Desktop
Per https://dev.acquia.com/blog/debugging-drupal-8/debugging-drupal-8-in-phpstorm-part-2-local-webbased-debugging-in-mac-os-x-acquia-dev-desktop-2-and-xdebug/17/08/2016/16426:
Tip per BW: A potential gotcha you may encounter with the below setup: If you forget to hang up the phone in any of your PHPStorm windows you will find that PHP commands/scripts from you terminal sessions mysteriously hang. For that reason I only use the phone when debugging drush code.
Phone + Chrome extension Xdebug Helper approach (see also Manual below):
1. Uncomment path to xdebug.so in appropriate php.ini file (/Applications/DevDesktop/php5_6/bin/php.ini):
At the very bottom of php.ini, add following two lines:
Restart DevDesktop and check xDebug via php.info (Dev Desktop > Preference > Config or admin/reports/status/php for a particular site)
2. In PhpStorm, make sure phone button (“Start listening for PHP debug connections”) is enabled
3. Chrome setup
a. Install Chrome extension Xdebug Helper
b. Leave all its settings default, you will not need to change anything for PhpStorm
c. Switch the grey Xdebug icon on Google Chrome toolbar to green
a. Install Chrome extension Xdebug Helper
b. Leave all its settings default, you will not need to change anything for PhpStorm
c. Switch the grey Xdebug icon on Google Chrome toolbar to green
4. Set breakpoints and Refresh browser with CMD+R
From https://dev.acquia.com/blog/debugging-drupal-8/debugging-drupal-8-in-phpstorm-part-2-local-webbased-debugging-in-mac-os-x-acquia-dev-desktop-2-and-xdebug/17/08/2016/16426:
In the “Frames” window at bottom-left side you can see the backtrace route of the script you are running. Similar to debug_print_backtrace() command, but with a significant difference: you can click on every trace and see actual variables when the function below was called. Incredibly helpful!
In the “Variables” window at bottom-right side you can see a list and values of variables currently available to the method you are inside. Objects and arrays are expandable, so you can jump inside. In addition to that:
You can see all PHP globals which are part of each PHP script
You can set values to simple variables like strings and continue running the code with changed variables
You can navigate forward in the script with the keyboard shortcuts or arrows near the Debugger tabs. You can step forward, step into method, step out, run to the cursor, set the list of methods to ignore and much more
You can not navigate backward in the script because of nature of the debugging. To navigate 'backward“ you need to stop debugging, set the breakpoint to the sooner state of the script and refresh the page.
In the “Frames” window at bottom-left side you can see the backtrace route of the script you are running. Similar to debug_print_backtrace() command, but with a significant difference: you can click on every trace and see actual variables when the function below was called. Incredibly helpful!
In the “Variables” window at bottom-right side you can see a list and values of variables currently available to the method you are inside. Objects and arrays are expandable, so you can jump inside. In addition to that:
You can see all PHP globals which are part of each PHP script
You can set values to simple variables like strings and continue running the code with changed variables
You can navigate forward in the script with the keyboard shortcuts or arrows near the Debugger tabs. You can step forward, step into method, step out, run to the cursor, set the list of methods to ignore and much more
You can not navigate backward in the script because of nature of the debugging. To navigate 'backward“ you need to stop debugging, set the breakpoint to the sooner state of the script and refresh the page.
Manual (not using Chrome extension Xdebug Helper:
/Applications/DevDesktop/php5_6/ext/xdebug.so
Edit php.ini, uncomment zend_extension
At the very bottom of php.ini, add following two lines:
Restart Acquia Drupal Stack, visit phpinfo() and confirm xdebug
Visit php.info via Dev Desktop > Preference > Config or
Visit phpinfo via admin/reports/status/php
Visit phpinfo via admin/reports/status/php
PhpStorm: Run > Edit Configurations: Add Php Web Application
Add Server: e.g., Host: d8-theming.dd, Port: 8083, Debugger: XDebug
If working, will open default browser (can set breakpoints to test)
Add Server: e.g., Host: d8-theming.dd, Port: 8083, Debugger: XDebug
If working, will open default browser (can set breakpoints to test)
Legal disclosures. Autodesk makes software and services available on a licensed or subscription basis. Rights to install, access, or otherwise use Autodesk software and services (including free software or services) are limited to license rights and services entitlements expressly granted by Autodesk in the applicable license or service agreement and are subject to acceptance of and compliance. SketchBook for Everybody! At Autodesk, we believe creativity starts with an idea. From quick conceptual sketches to fully finished artwork, sketching is at the heart of the creative process. Autodesk sketchbook brushes.
If you get error: 'PHP Interpreter is not configured':
- Click 'configure PHP interpreter'
- Click '+' sign and add path to php
- /usr/local/bin/php
- Should select Php 5.6.14
Set breakpoint(s), then
Debug 'd8-theming.dd' will launch:
Troubleshooting
If your debugger is not being triggered, PHPStorm has a validation script you can use to detect problems in your configuration.
In my case, PHPStorm was loading the php.ini for ADD PHP version 7.1 even though the site was running PHP 5.6. I edited the php.ini in the 7_1 folder to include the three necessary lines and then debugging was triggered. Not sure if there are going to be problems debugging a 5.6 site with PHP 7.1.
Older 2013 approach
- If using Acquia Dev Desktop, likely already has xdebug extension (/Applications/acquia-drupal/php5_3/ext/xdebug.so)
- Edit php.ini file:
- Restart Acquia Drupal Stack, visit phpinfo() and confirm xdebug
- PhpStorm: Run > Edit Configurations: Add Php Web Application
- Add Server: e.g., Host: mysite.localhost, Port: 8082, Debugger: XDebug
- If working, will open default browser (can set breakpoints to test), e.g.: http://mysite.localhost:8082/?XDEBUG_SESSION_START=14430
XDebug with brew-installed PHP
Setup the homebrew-php tap
Add xdebug for the phpversion(s) that you've installed:
brew will add the zend_extension line to a conf.d/ file like /usr/local/etc/php/5.5/conf.d/ext-xdebug.ini:
The lines below that are the xdebug config that I use. 'max_nesting_level' is the most important one.
xDebug configuration for debugging Drush commands
If you are using path mappings in your project you should set this variable [ref|https://blog.jetbrains.com/phpstorm/2012/03/new-in-4-0-easier-debugging-of-remote-php-command-line-scripts/]:
To tell PhpStorm which path mapping configuration it should use for a connection from a certain machine you need to set the value of the “PHP_IDE_CONFIG” environment variable to “serverName=SomeName”, where ‘SomeName’ is the name of the server configured in ‘Project Settings | PHP | Servers’.
Now for the magical setting that makes drush work ([Thanks Moshe|https://github.com/drush-ops/drush/issues/1938#issuecomment-175226384].): phpStorm Preferences > Languages > PHP > Debug: Set Max simultaneous connections to something like 19!
Now you should be able to set a break point in a hook_update_N and break at it when you run
drush updb -y
.Connect to Database(s)
- From Database panel, create new data source with command+N
- Select 'MySQL Connector/J-5.1.22' for driver files
- Download files (mysql-connector-java-5.1.22-bin.jar and mysql-connector-license.txt) - add to .gitignore if saving to repo
- Enter DatabaseURL (jdbc:mysql://[host][,failoverhost..][:port]/[database]), user, password
- Get Pantheon database connection info from Apollo dashboards
- Use Console button for sql command line
- In 'Schemas & Tables' tab, specify schema to select tables for retrieval and/or set default:
http://www.jetbrains.com/phpstorm/webhelp/db-data-source-properties.html#d97128e696
Resolving Conflicts
- Select VCS > Git > Resolve Conflicts
- If you know you want to 'Accept Yours' or 'Accept Theirs' for ALL modifications, you can do so from this screen.
- Otherwise, click the 'Merge' button to get a 3 panel comparison screen that will allow you to walk through each modification and decide which version to keep (click the double arrows from the left or right panel to accept the modification, which will show up in the center panel).
- When finished, you'll need to commit your changes per your normal process.
Enable Live Templates for Drupal Hook Completion
Before doing the 'push' command above:
Start phpStorm and Cmd-, then search for Keymap. Then search keymap for 'template.' For me ^J is 'insert live template.'
Type hook_menu_alt^J[Enter]
and see:
Major Version Upgrades
When upgrading from v8 to v9 I found that I couldn't just use phpStorm > Check for Updates. Instead:
- Download the latest .dmg for the new version
- In Finder visit Applications and rename your current phpStorm.app
- Drag the new phpStorm.app to Applications.
- Launch the new app
- You will be prompted to import your settings (which live in ~/.Webide*/)
- You'll be prompted to apply our license. I do this with the 'login to JetBrains' option.
Optional
- PhpStorm Quickstart: http://www.jetbrains.com/phpstorm/quickstart/index.html
- PHP Code Sniffer: https://drupal.org/node/1419988
- Drupal Plugin for Drupal-specific features (part of Php Storm 7 Early Access Program beginning July 2013): http://blog.jetbrains.com/phpstorm/2013/07/drupal-development-using-phpstorm/
Tips
Compare Git Branches
- Checkout specific branch
- VCS > Git > Compare with Branch..
- Select branch to compare with:
- PHP Storm will show files that have changed (in blue by default)
Phpstorm Drupal 9 Crack
- Double-click the file to see the side-by-side comparison
Show Changes View
- VCS > Show Changes View to display recent local changes (e.g., pending commit)
- Can then select a specific file and then select the icon for 'Show diff' to display side-by-side comparison
Debugging cli scripts that call exec()
(This probably applies to other functions like fork() as well.)
Our automation scripts use exec() to call drush and terminus. If you place a breakpoint after the first exec() in the code the debugger will hang and you have to hit ^C (or the stop button on the phpStorm debug pane). I asked David Snopeck if there was a way to debug through exec()s and he said:
So, the way xdebug works is that your PHP process attempts to connect to your debugger process (usually the IDE) at a particular host/port which is configured in php.ini (xdebug.remote_host and xdebug.remote_port). If you could have a 2nd debugger running on a different port, and somehow exec() the 2nd PHP process with a different php.ini (via: 'php --php-ini other-php.ini actual-php-script.php' or something) which points at that port, then the 2nd debugger *should* debug the 2nd process.
Today (whille using phpStorm 9) I discovered a workaround:
- Place a breakpoint after an exec()
- Select Run > Break at first line in PHP scripts. (Optional: Helps you verify that the debugger has fired up.)
- Enable 'Start listening for debug connections'
- Execute the script from the terminal.
- Hit F9 to continue when it breaks at the first line.
- The debugger will hang. I wait a reasonable period for the exec() code to return then I disable 'listening for debug connections' and the script hit's the break point after the exec and I can continue debugging.
I'm not sure what happens if you hit another exec(). Maybe as soon as debugging resumes, you could re-enable 'listening for debug connections' and follow the same pattern.
Resources
The phpStorm Blog is interesting to follow.
The phpStorm Video Tutorials are nice too.
Known Issues
PhpStorm 7.1.3: Git merge freezes after resolving conflicts
Description: When using VCS > Git > Resolve Conflicts after resolving the last conflict, PhpStorm will crash (must Force Quit to get out of application). This is a known issue.
- Workaround: If you press the <return> key immediately after resolving the last conflict the keyboard focus is still on the hidden dialog and it applies the merge (and presumably the <esc> key will cancel it).
Solution: Instead of using the Workaround, this can be fixed via the following steps:
- Press Cmd+Q: If you see the dialog at the top as a 'sheet' you likely have the bug
- Press Cmd+Alt+Shift+/ and choose 'Registry' from the popup
I think it's Ctrl+Alt+Shift+/ (not CMD) - In the registry dialog find the key: ide.mac.message.dialogs.as.sheets and uncheck it.
- Close the window (The ticket says 'Use the cross button in the top left corner of the window. Not the Close button' but closing via button seemed to work fine for me too.)
- Press Cmd+Q: Once fixed, the dialog should show up as a normal prompt
Note: Setting 'ide.mac.message.dialogs.as.sheets=false' to /Applications/PhpStorm/bin/idea.properties sounds like it works too, but the above seems like an easier way to keep track of registry values.
When using OSX and XDebug, unable to see long string values
Update: Appears to be fixed with Php 7.1.3
'Click to see the full value' link does not work.
Open JetBrains ticket: http://youtrack.jetbrains.com/issue/WI-17166#
Workaround: Right-click the variable and select 'Copy Value' then paste to a new text file.
The question I get asked most often when discussing my Lando development environment with other Drupal Web Developers is, “How do you setup Lando and PhpStorm to debug Drupal using Xdebug?” This blog post will help you do exactly that.
Before you start, you should have a Drupal website up-and-running in Lando. Even a freshly-installed, blank Drupal website will do.
Once you finish, you will be able to use PhpStorm to:
- Debug Drupal 8 (and 7) in Lando: a Docker-based development environment
- Debug drush commands for Drupal in Lando
- Debug phpunit tests for Drupal in Lando
- because if you had just written your unit test before you wrote that snazzy method, like you were supposed to,…?
Tested using:
- OSX
- v10.12.6
- v10.13.6
- PhpStorm v2018.2.2
- Xdebug v2.6.1
- Lando v3.0.0-beta.47
- Docker v18.06.1-ce-mac73 (26764)
- Drupal
- v8.6.0
- v7.59
- drush v8.1.17
- NOTE: drush 9 is currently NOT supported in PhpStorm
- phpunit
- v6.5.12 for Drupal 8
- v6.5.3 for Drupal 7
Prerequisites:
Phpstorm Drupal 9 Download
- PhpStorm is installed
- Xdebug is installed
- Lando is installed (includes Docker)
- Drupal is installed in Lando
- drush 8.x.x is installed
- NOTE: drush 9 is currently NOT supported in PhpStorm
- phpunit 6.5.x is installed
- Drupal 8: included with install
- Drupal 7: https://phpunit.de/manual/6.5/en/phpunit-book.html#installation
- You should be reasonably familiar with the command line, as well as with the above software.
Prepare your Drupal in Lando for PhpStorm:
Create a custom php.ini for your Drupal in Lando website:
In the root directory of your lando project, create a “config” directory.
- For example, on OSX this might be: ~/Sites/yourdrupal.lndo.site/config/
Inside this config directory, create a php.ini file with the following:
Edit the .lando.yml file for your Drupal in Lando website:
Add the following to the “config” key of the .lando.yml file, so that Lando will include your new php.ini.
Add the following to the “services” key of the .lando.yml file, so that Lando will include a PHP_IDE_CONFIG for PhpStorm.
Change “yourdrupal.lndo.site” above to match the domain name of your Drupal in Lando website.
Add the following to the “tooling” key of the .lando.yml file, so Lando will recognize “lando phpunit” commands.
If Drupal 8:
Change “web” above to match the webroot directory of your Drupal 8 in Lando website.
If Drupal 7:
Examples of complete Drupal 8 and Drupal 7 .lando.yml files:
A complete but basic Drupal 8 .lando.yml configured for PhpStorm would look like the following:
A complete but basic Drupal 7 .lando.yml configured for PhpStorm would look like the following:
In fact, you could use either of the above .lando.yml files as written, just to test things out. If you plan on spinning-up both of them on the same machine at the same time, though, change the value in “name:” and “PHP_IDE_CONFIG:” of at least one of them first. ?
Rebuild your Drupal in Lando website in order to apply the new settings.
Create a new PhpStorm Project for your Drupal in Lando website:
Open PhpStorm and click on the following:
File > New Project from Existing Files
- Source Files are in a local directory, no Web server is yet configured
- Click on the “Next” button.
Mark as Project Root a directory to create the project in:
- Click on “Project Root”
- (in the top left window toolbar).
- Select your drupal root directory.
- For example, /Users/You/Sites/yourdrupal.lndo.site/web
- Click on the “Finish” button.
Enable Drupal Support:
After the project finishes indexing, the Event log window should be visible. If it isn’t, click on “Event log” in the bottom-right of the screen.
In the Event log window, enable the suggested items by clicking on them:
- Enable the Symfony Plugin with auto configuration now
- (may or may not be available)
- Enable Drupal Support, which should display the “Enable Drupal Integration” configuration window below.
Enable Drupal integration:
- Verify that “Enable Drupal integration” is checked.
- Drupal installation path: (Select your drupal root directory)
- For example, /Users/You/Sites/yourdrupal.lndo.site/web
- Verify that “Set up PHP | Include paths” is checked
- Version: 8
- (or whatever Drupal version you are using)
- OK
The above configurations can also be set at:
- PhpStorm > Preferences > Languages & Frameworks > PHP > Frameworks
If prompted by the Event log window, “Set Drupal-style formatting for this project”.
Configure your PhpStorm project:
Setup the PHP Interpreter for the project:
- PhpStorm > Preferences > Languages & Frameworks > PHP
- PHP language level: 7.1
- (or whatever PHP version your Drupal in Lando website uses).
- Click on the “…” icon to the right of the “CLI Interpreter” field.
In the window that opens,
- control+n
- (or click on the “+” icon at the top left of the pane).
- Select “From Docker…”
- Server: Docker
- Image Name: devwithlando/php:7.1-apache
- (or whatever PHP version your Drupal in Lando website uses)
- PHP interpreter path = php
- OK
- Apply
- OK
- Apply
Setup the PHP Server for the project:
- PhpStorm > Preferences > Languages & Frameworks > PHP > Servers
- Click on the “+” in the top left of the left pane.
- Name: yourdrupal.lndo.site
- (Change this to match the domain name of your Drupal in Lando website.)
- Host: yourdrupal.lndo.site
- (Change this to match the domain name of your Drupal in Lando website.)
- Port: 80
- (or whatever lando provided, if applicable)
- Debugger: Xdebug
- Enable: “Use path mappings”
Set the path mapping for the Drupal in Lando website’s root directory:
In the “File/Directory” column, highlight the (path to your Drupal root) row that is listed under the “Project files” folder, by clicking on it.
- For example, click on: /Users/You/Sites/yourdrupal.lndo.site/web
- Edit the “Absolute path on the server” field for the highlighted row.
- Click on the highlighted edit icon that is visible on the right of the same row.
- Type: /app/web
- Press the enter key to update the field.
- Apply
Set the path mapping for drush in Lando:
If Drupal 8:
In the “File/Directory” column, highlight the (path to your included drush) row that is listed the under the “Include path” folder, by clicking on it:
- For example, click on: /Users/You/Sites/yourdrupal.lndo.site/web/vendor/drush/drush
- Edit the “Absolute path on the server” field for the highlighted row.
- Click on the highlighted edit icon that is visible on the right of the same row.
- Type: /usr/local/bin/drush
- Press the enter key to update the field.
- Apply:
If Drupal 7:
In Terminal, add a symlink at your Drupal web root to your globally-installed drush
- For example, on OSX:
In PhpStorm, highlight your newly created “drush” symlink row that is listed the under the “Include path” folder, by clicking on it.
- Edit the “Absolute path on the server” field for the highlighted row.
- Click on the highlighted edit icon that is visible on the right of the same row.
- Type: /usr/local/bin/drush
- Press the enter key to update the field.
- Apply
Configure PhpStorm to debug browser-triggered events for your Drupal in Lando website:
- PhpStorm > Preferences > Languages & Frameworks > PHP > Debug
- External Connections
- Enable “Break at first line in PHP scripts”
- (to at least verify that the debug session is working)
- Max simultaneous connections = 19
- Press the tab key to update the field.
- Enable “Break at first line in PHP scripts”
- Apply
Configure PhpStorm to debug “lando drush” commands for your Drupal in Lando website
- PhpStorm > Preferences > Tools > Command Line Tool Support
- control+n
- (or click on the “+” icon on the left side of the main pane)
- Select “Custom tool” (not “Drush”) from the dropdown menu.
- We don’t select “Drush” here because the path to the Lando appserver’s drush must be entered manually.
- Visibility = project
- OK
- Set the path to the Lando appserver’s drush:
- /usr/local/bin/drush
- Alias: drush
- OK
- Show console in: tool window
- Apply
- OK
Test your Drupal in Lando PhpStorm Debugging Setup:
Start listening for PHP debug connections:
- command+shift+L in PhpStorm
In your web browser, reload your Drupal in Lando website. You do NOT need an Xdebug Helper browser extension for this to work. With the above settings, PhpStorm will automatically pause your website at:
- If Drupal 8: line 14 (“$autoloader) of index.php
- If Drupal 7: line 17 (“define”) of index.php
Note: PhpStorm did NOT automatically focus the PhpStorm application in your computer display. With the current PhpStorm settings, you have to switch to PhpStorm manually in order to see that it is pausing your website. We will change this setting in the next step.
fn+command+F2 to stop debugging but continue listening for PHP Debug Connections
To focus PhpStorm automatically when a breakpoint is set:
- PhpStorm > Preferences > Languages & Frameworks > PHP > Debug > External connections
- Uncheck “Break at first line in PHP scripts”.
- Apply
- OK
Test browser-triggered debugging:
If Drupal 8:
- Add a breakpoint at line 14 (“$autoloader”) of web/index.php
- Add a breakpoint at line 236 (“function user_load”) of web/core/modules/user/user.module
If Drupal 7:
- Add a breakpoint at line 19 (“require_once”) of web/index.php
- Add a breakpoint at line 365 (“function user_load”) of web/core/modules/user/user.module
In your web browser, navigate to yourdrupal.lndo.site/user/1
- Focus will switch to PhpStorm and catch at the breakpoint in index.php.
- fn+F9 to jump to the next breakpoint.
- PhpStorm will catch at the breakpoint in user.module.
- fn+command+F2 to stop debugging but continue listening for PHP Debug Connections
Test “lando drush” debugging:
In Terminal:
- PhpStorm will catch at the breakpoint that is still set for user.module in the example above.
- fn+command+F2 to stop debugging but continue listening for PHP Debug Connections
Test phpunit debugging:
If Drupal 8:
- Add a breakpoint at line 62 (“$this->password”) of web/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
- Run a phpunit test in Terminal:
- Focus will switch to PhpStorm and catch at the breakpoint in PasswordHashingTest.php.
- fn+command+F2 to stop debugging but continue listening for PHP Debug Connections
- You may have to fn+command+F2 more than once
If Drupal 7:
- Enable the Testing module:
- Remove the breakpoint you set above at line 365 (“function user_load”) of web/core/modules/user/user.module
- Add a breakpoint at line 23 (“require_once”) of web/modules/simpletest/tests/password.test
- Run a phpunit test in Terminal:
- Focus will switch to PhpStorm and catch at the breakpoint in password.test
- fn+command+F2 to stop debugging but continue listening for PHP Debug Connections
- You may have to fn+command+F2 more than once
Happy Drupal in Lando debugging with PhpStorm!
Have your own tricks for Drupal debugging? Share your thoughts with us on Twitter, and subscribe to our newsletter for more content like this!