In this debugging mode, PhpStorm fully controls the debugging process: it launches the application, opens the browser, and activates the debugging engine according to a PHP Web Application debug configuration.
A PHP Web Application debug configuration tells PhpStorm where the PHP application to debug is deployed, the URL address to access the starting page of the application, the browser to open the starting page in, and the correspondence between files and folders deployed on the server and their local copies (mappings).
Mappings are necessary for the following reason. During the debugging session on the local or remote server, the server side of the debugger tells PhpStorm the name of the currently processed file and the number of the line to be processed. PhpStorm opens the local copy of this file and indicates the line with the provided number. This behaviour is enabled by specifying correspondence between files and folders on the server and their local copies. This correspondence is called mapping.
You can also specify the scripts requests to which you want PhpStorm to ignore during debugging. This approach can be useful, when your application contains scripts that use AJAX. Suppose you have a menu-ajax-script.php that "reloads" a part of your web page. This script works properly so you do not need to debug it. However, this script is still requested during the debugging session. To have incoming connections to this script ignored, add the menu-ajax-script.php script to the skipped paths list. You can also group such scripts into folders and add these folders to the "ignore list".
On this page:
- Preparing the debugging engine
- Setting the breakpoints
- Creating a PHP Web Application debug configuration
- Defining a debug server configuration
- Initiating a debugging session and examining the suspended program
- Specifying scripts to skip requests to
Preparing the debugging engine
Before you start debugging, make sure that you have a debugging engine installed and configured properly. PhpStorm supports debugging with two most popular tools: XDebug and Zend Debugger. These tools cannot be used simultaneously because they block each other. To avoid this problem, you need to update the corresponding sections in the php.ini file. To find out which php.ini file is active, create and run a test file with phpinfo(), then search for the Loaded Configuration File.
For more information on configuring debugging engines, see Configuring XDebug, Configuring Zend Debugger, http://confluence.jetbrains.com/display/PhpStorm/Xdebug+Installation+Guide, and http://confluence.jetbrains.com/display/PhpStorm/Zend+Debugger+Installation+Guide.
Breakpoints are source code markers used to trigger actions during a debugging session. Typically, the purpose behind setting a breakpoint is to suspend program execution to allow you to examine program data. However, PhpStorm can use breakpoints as triggers for a variety of different actions. Breakpoints can be set at any time during the debugging process. Your breakpoints don't affect your source files directly, but the breakpoints and their settings are saved with your PhpStorm project so you can reuse them across debugging sessions.
Place the caret on the desired line of the source code.
Breakpoints can be set in the PHP context inside *.php, *.html, and files of other types. Only executable lines are valid locations for line breakpoints. Comments, declarations, and empty lines are not valid locations for the
Do one of the following:
- Click the left gutter area at a line where you want to toggle a breakpoint.
- On the main menu, choose .
- Press Ctrl+F8Ctrl+F8Ctrl+8Ctrl+F8Ctrl+F8F9Ctrl+F8Ctrl+Shift+B or Ctrl+F8Command F8Command F8Shift Command B.
Open the Run/Debug Configuration dialog box by doing one of the
- On the main menu, choose .
- Press Shift+Alt+F10Shift+Alt+F10Shift+Alt+F10Shift+Alt+F10Shift+Alt+F10Shift+Alt+F10Shift+Alt+F10Shift+Alt+F10Control Alt RShift Alt F10Control Alt R, then press 0 to display the Edit Configuration dialog box or select the configuration from the pop-up window and press F4F4F4F4F4F4F4F12 or Ctrl+Shift+ECommand Down or F4F4F3.
- Click on the toolbar or press InsertInsertInsertInsertInsertInsertInsertInsertShift BackspaceInsertShift Backspace. From the drop-down list, select the PHP Web Application configuration type. The PHP Web Application dialog box opens.
- Specify the configuration name.
- Choose the applicable debug server configuration from the Server drop-down list or click the Browse button and define a debug server configuration in the Servers dialog box that opens.
In the Start URL text pox, type the server path to the file that implements the
application starting page.
Specify the path relative to the server configuration
The read-only field below shows the URL address of the application starting page. The URL address is composed dynamically as you type.
- Specify the browser to open the application in. Choose a configured browser from the Browser drop-down list or click the Browse button and specify another browser in the Web Browsers dialog box that opens.
- To have the debugging engine stop as soon as connection between it and PhpStorm is established (instead of running automatically until the first breakpoint is reached), select Stop at first line check box.
Open the Servers dialog box by doing one of the following:
- Choose Servers under the PHP node. for Windows and Linux or for Mac OS. Then click
- In the Run/Debug Configuration: PHP Web Application dialog box, click the Browse button next to the Server drop-down list.
- Specify the server configuration name.
- Specify the host where the application is run and the port to access it.
- From the Debugger drop-down list, choose the debugging engine to use.
Specify how the PhpStorm will set up a correspondence between files on the server and their local copies.
Based on these mappings,
PhpStorm will open local copies of currently processed files.
To have PhpStorm suggest mappings itself, clear the Use path mappings
When you start a debugging session, PhpStorm will try to detect the local copies of the application
files on the server.
The suggestions are displayed in a dialog box where PhpStorm asks you to confirm or edit suggested
PhpStorm detects mappings 100% correctly if the application is deployed to the server root and the folder structure on the server is identical with the folder structure under the project root.
- To specify correspondence between files on the server and their local copies manually, select the Use path mappings check box and map files and folders on the server to their local copies.
- To have PhpStorm suggest mappings itself, clear the Use path mappings check box. When you start a debugging session, PhpStorm will try to detect the local copies of the application files on the server. The suggestions are displayed in a dialog box where PhpStorm asks you to confirm or edit suggested mappings.
- To start debugging, click the Debug button on the toolbar.
- As soon as the debugger suspends on reaching the first breakpoint, examine the application by analyzing frames. A frame corresponds to an active method or function call and stores the local variables of the called method or function, the arguments to it, and the code context that enables expression evaluation. All currently active frames are displayed on the Frames pane of the Debug tool window. where you can switch between them and analyze the information stored therein in the Variables and Watches panes. For more details, see the section Examining Suspended Program.
Continue running the program and examine its frames as soon it is suspended.
- To control the program execution manually, step through the code using the commands under the F7F7F7F7F7F11 or F8F7F5F7F7F5), (Shift+F8Shift+F8Shift+F8Shift+F8Shift+F8Shift+F11 or Ctrl+Shift+F8Ctrl+F7F7 or Shift+F8Shift F8Shift F8F7), (F8F8F8F8F8F10 or Shift+F8F8F6F8F8F6), and others. For more details, see Stepping Through the Program. menu or toolbar buttons: (
- To have the program run automatically up to the next breakpoint, resume the session by choosing F9F9F9F9F9F5F5F8 or F9Alt Command RF9F8 or pressing
This approach can be useful, when your application contains scripts that use AJAX. Suppose you have a menu-ajax-script.php that "reloads" a part of your web page. This script works properly so you do not need to debug it. However, this script is still requested during the debugging session. To have incoming connections to this script ignored, add the menu-ajax-script.php script to the skipped paths list. You can also group such scripts into folders and add these folders to the "ignore list".
- Open the Project Settings, click Debug under the PHP node, then click Skipped Paths.
On the Skipped Paths page that opens, configure an "ignore list" of scripts
and folders with scripts not to be invoked if PhpStorm receives incoming connections to them.
- To add a new entry to the list, click the Add button or press Alt+InsertAlt+InsertAlt+InsertAlt+InsertAlt+InsertAlt+InsertAlt+Insert or Ctrl+NAlt+InsertCommand N or Control EnterControl N or Control EnterCommand N or Control Enter. Then click the Browse button and in the dialog box that opens choose the file or folder to skip connections to.
- To remove an entry from the list, select it and click the Remove button or press Alt+DeleteAlt+DeleteAlt+DeleteAlt+DeleteAlt+DeleteAlt+DeleteAlt+DeleteAlt+DeleteCommand Delete or Command BackspaceCommand DeleteCommand Delete or Command Backspace. The script will be now executed upon receiving requests to it.
- To have PhpStorm inform you every time it receives a request to a script to be skipped, select the Notify about skipped paths check box.