This tutorial describes how to get started with PHP web application debugging in PhpStorm IDE using Xdebug. Configuration for Zend Debugger is very similar (just follow Zend Debugger installation guide and proceed from step 2 of this tutorial).
|Table of Contents|
1. Install Xdebug
In order to To use Xdebug with PhpStorm for debugging PHP applications, you should need to have a PHP development environment configured with Xdebug extension installed and this . This task is beyond PhpStorm’s control. More information on configuring PHP development environment can be found at in our webhelpweb help.
Make sure that you have Xdebug installed properly. Please note that your Xdebug version should fit the PHP interpreter version you have (mind the PHP version number and thread-safe/non-thread-safe option) and installed as zend_extension. Don’t forget to set the xdebug.remote_enable setting to 1 in php.ini file. Information about Xdebug installation and configuration Detailed information on installing and configuring Xdebug can be found here. You can download the latest version of the Xdebug plugin at the its official web sitewebsite. Recommended stable versions are 2.2.1 or 2.1.3.
You can check the configuration by executing php --version in the terminal
or Alternatively, execute a page with phpinfo(); php PHP function and check make sure that you have Xdebug extension enabled - . The xdebug section of the document with the installed version should be available.
2. Prepare PhpStorm
Toggle the “Listen debugger connections“Start Listening for PHP Debug Connections” button. Don’t use any run configurations.
Once you've installed and configured Xdebug, you can use the Validating Your Debugging Configuration tool to confirm that the configuration of Xdebug and PhpStorm are compatible.
3. Set a breakpoint in the source code
Apart from setting the breakpoint manually, you can use an the option Run | Break at first line in PHP scripts in order to have an automatic breakpoint at the first line of every PHP script you debug.
4. Activate debugger on server
In order to activate the debugger, you need to set a special GET/POST or COOKIE parameter (more click here for details). You can do it manually, but it is much more convenient to use one of the a special tools tool such as browser toolbars toolbar or bookmarklets bookmarklet for that.
Try our PhpStorm bookmarklets generator and get bookmarklets which will work in any modern browser and allow you to start/stop a debugging session by controlling the Xdebug cookie.
Names of menus and options can may vary - depends on you internet browser. We’ve used Firefox for this sectiondepending on your Internet browser. This section uses Firefox.
4.1. Make Enable your Bookmarks Toolbar enabled (View | Toolbars | Bookmarks Toolbar)
4.2. Open Go to http://www.jetbrains.com/phpstorm/marklets/ address
4.3. Click the Generate button under the Xdebug section, then drag -and-drop the links “Start debugger” and “Stop debugger” from appeared the Debug section that appears to the Bookmarks Toolbar.
5. Start a debug session in browser
7. Set initial path mappings
Switch to PhpStorm and set the initial path mappings by selecting the path to the local copy of the script that we are debugging. These paths are similar if you are editing files directly on the server. The “Incoming Connection” dialog should appear automatically.Image Removed; you'll see the Incoming Connection From Xdebug dialogue. You'll now need to select the path mappings so that PhpStorm can map the remote files on the web server to the local files in your project. If you have a deployment configured, then PhpStorm will offer to configure the mappings based on the paths you've already set in that deployment.
If you have no deployment configured (or if the file mappings in the deployment are different), then you can select a manual file to use for this incoming debugger session.
On After reaching the breakpoint the debugger suspendsis suspended. Now let’s investigate the application.
The first thing to check is that the Xdebug configuration is compatible with PhpStorm's configuration, you can do that using the Validating Your Debugging Configuration tutorial.
In some cases you may get an the error message “Remote file path ‘path/to/script/on/the/server.php’ is not mapped to any file path in project“ or “The script ‘path/to/script/on/the/server.php’ is outside the project.” . This means that PhpStorm does is not know sure which local file corresponds to the specified remote file path.
You can solve this problem quickly. Just set up the necessary path mappings by clicking the relevant link.