Xdebug.remoteenable = 1 xdebug.remoteautostart = 1 Tip! If your PHP project runs in a Docker container, you need also to add the following line to the xdebug.ini file, where 172.17.0.1 is the IP address of the docker0 interface on your computer (on Mac OS you have to put host.docker.internal instead). To set up Xdebug, you need to configure a file in your Git repository, configure your IDE, and set up port forwarding. You can configure settings in the magento.app.yaml file. After editing, you can push the Git changes across all Starter environments and Pro Integration environments to enable Xdebug.
Xdebug Cli Config
Xdebug is an extension for debugging your PHP code. Magento Cloud Docker provides a separate container to handle Xdebug requests in the Docker environment. Use this container to enable Xdebug and debug PHP code in your Docker environment without affecting your Magento Commerce Cloud project configuration.
The following instructions explain how to configure Xdebug and PhpStorm to debug in your local Docker environment.
If you use Microsoft Windows, take the following steps before continuing:
- Open your Docker settings.
- Select the Expose daemon on tcp://localhost:2375 without TLS checkbox.
- Wait for the settings to apply.
Enable Xdebug
To enable Xdebug for your Docker environment, generate the Docker Compose configuration file in developer mode with the
--with-xdebug
option and any other required options, for example.For Linux systems, you must use the
--set-docker-host
option to add thehost.docker.internal
entry to the/etc/hosts
file for thefpm_xdebug
container.This command adds the Xdebug configuration to your
docker-compose.yml
file.Follow the steps to launch the Docker environment in Developer mode.
The default Docker environment configuration sets the following Xdebug configuration variables:
Change any Xdebug configuration using the
XDEBUG_CONFIG
option. For example, to change the xdebug.remote_port option:On Linux systems, use the following command instead:
To configure PhpStorm to work with Xdebug:
In your PhpStorm project, open the settings panel.
- Mac OS X—Select File > Preferences.
- Windows/Linux—Select File > Settings.
In the Settings panel, expand and locate the Languages & Frameworks > PHP > Servers section.
Click the + to add a
PHP Remote Debug
server configuration. The project name is in grey at the top.Configure the following settings for the new server configuration:
- Name—Enter the name used for the
serverName
option fromPHP_IDE_CONFIG
value. - Host—Enter
localhost
. - Port—Enter
80
. - Debugger—Select
Xdebug
.
- Name—Enter the name used for the
Select Use path mappings. In the File/Directory pane, the root of the project for the
serverName
displays.In the Absolute path on the server column, click and add a value to the
MAGENTO_ROOT
option. The default value is/app
Change the Xdebug port to 9001 in the Languages & Frameworks > PHP > Debug > Xdebug > Debug Port panel.
Click Apply.
Use Xdebug
The following steps describe debugging web requests and CLI commands.
To debug web requests:
In your PhpStorm project, click (Start listening) in the top navigation bar.
Add breakpoints in the
pub/index.php
file.Install the debug extension in the browser, and then click Debug to enable.
In the browser, open the
https://localhost
URL.When PhpStorm recognizes the Xdebug connection, you can begin debugging web requests.
You can debug any Magento command or PHP script using the following steps.
To debug CLI commands:
In your PhpStorm project, open the Build, Extension, Deployment > Docker panel, and then click
+
to add a new Docker server and update the following settings:- Name—Enter a name for the server, for example
Docker Cloud
. - Connect to Docker daemon with—
- Windows—Select TCP socket and update Engine Api Url with
tcp://localhost:2375
. - Mac OS X—Select Docker for Mac. [default]
- Windows—Select TCP socket and update Engine Api Url with
- Name—Enter a name for the server, for example
In the Languages & Frameworks > PHP > Cli Interpreter panel, click […].
Click [+] to add and configure a new Cli Interpreter from your Docker image. Update the following settings:
- Name—Enter a name for the new interpreter, such as
Magento cloud docker cli
. - Remote—Select
Docker
.- Server—Select
Docker Cloud
from the previous step. - Image name—Select
magento/magento-cloud-docker-php:7.x-cli
.
- Server—Select
- Additional > Debugger extension—
- Windows—Enter
xdebug
. - Mac OS X/Linux—Enter
xdebug.so
.
- Windows—Enter
- Click Refresh to verify that the interpreter and Xdebug extension are configured properly.
- Name—Enter a name for the new interpreter, such as
Click Save.
Open the Run/Debug Configuration window and add a new PHP script with the following settings:
- Name—Enter
bin/magento
. - Configuration > File—Select the path to the
bin/magento
file in your local environment.
- Name—Enter
Add breakpoints in the
bin/magento
file and the debug PHP script created in the previous step.
Using Xdebug Helper
You can install and use the Xdebug Helper Chrome extension to debug your PhP code from the browser.
To use Xdebug Helper with Chrome:
Install the Xdebug Helper extension from the Chrome store.
Enable the extension in Chrome as shown in the following figure.
In Chrome, click in the Chrome toolbar.
From the Xdebug helper menu, click Options.
From the IDE Key list, select PhpStorm.
Click Save.
PHP applications are not always web applications. Various command line tools, daemons, message queue processing applications and other types of applications typically run in the PHP CLI. There are several ways to start a PHP CLI debugging session. You can start it from within PhpStorm and make it start the script and attach the debugger to it. Alternatively, you can let PhpStorm listen for incoming debugger connections and start the script outside the IDE. We'll take a look at both options.
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 as described in Configure Xdebug and Configure Zend Debugger.
Open the active php.ini file in the editor:
In the Settings/Preferences dialog Ctrl+Alt+S, click PHP.
On the PHP page that opens, click next to the CLI Interpreter field.
In the CLI Interpreters dialog that opens, the Configuration file read-only field shows the path to the active php.ini file. Click Open in Editor.
Start a debugging session from PhpStorm
To start debugging a PHP CLI script from within PhpStorm, perform the following steps.
Create a Run/Debug Configuration
PhpStorm uses Run/Debug configurations to execute a script from within the IDE. A configuration can define additional arguments for the PHP interpreter as well as launch other commands prior to starting our script. We will need a Run/Debug configuration to start the debugger from within PhpStorm.
Create a Run/Debug configuration for a PHP script manually
Create a new Run/Debug configuration using the Run | Edit Configurations menu.
Add a new configuration of the PHP Script type and provide the required parameters, such as the script to be executed.
Save the created Run/Debug configuration.
Generate a Run/Debug configuration for a PHP script
Right-click in the Project tool window, and select Debug | <script name>.php from the context menu (make sure to pick the item marked with ). Alternatively, open the script in the editor, press Alt+Shift+F9, and select the script to be debugged.
The IDE will launch the script with the debugger enabled, and open the Debug tool window.
Launch the Debugger
Before launching the debugger, make sure that either a breakpoint is set or the Break at first line in PHP scripts option is enabled on the Debug page of the Settings/Preferences dialog Ctrl+Alt+S.
Click on the PhpStorm toolbar.
Press Alt+Shift+F9.
Select Run | Debug from the main menu.
Switch between configured PHP interpreters on the fly
Press Ctrl+Shift+A and start typing
Change PHP interpreter
. In the suggestions list, select the Change PHP interpreter action.If necessary, you can assign a keyboard shortcut for this action either directly in the suggestions list by pressing Alt+Enter, or at a later point as described in Configure keyboard shortcuts.
In the popup menu that opens, select one of the configured local or remote PHP interpreters.
The selected interpreter will be set as the default project interpreter on the PHP page of the Settings/Preferences dialog Ctrl+Alt+S. This will also affect the run/debug configurations, test frameworks', and quality tools' configurations that are set to use the default project interpreter.
Start a debugging session from the command line
Before you start a debugging session with PhpStorm when running CLI scripts, make sure that any of the following requirements is met:
Xdebug's
remote_autostart
(for Xdebug 2) orstart_with_request
(for Xdebug 3) option is enabled.XDEBUG_CONFIG
environment variable exists.
Listening for incoming debugger connections
In PhpStorm, enable listening to incoming debug connections by either clicking on the toolbar or selecting Run | Start Listening for PHP Debug Connections. This will ensure PhpStorm reacts when a debugging session is started and opens the debug tool window automatically. Before launching the script, make sure that either a breakpoint is set or the Break at first line in PHP scripts option is enabled on the Debug page of the Settings/Preferences dialog Ctrl+Alt+S.
Command Line Xdebug
Start the script with debugger options
Since we'll be starting the script from the command line, we will have to make sure it is started with the required settings to enable the debugger.
Starting the script with Xdebug
Xdebug has various configuration options which we can use to let the PHP interpreter reach out to PhpStorm. These parameters have to be passed to the PHP interpreter using the -d
command line parameter. Alternatively, you can set an environment variable so that you don't need to provide the -d
parameters every time.
Start the script with debugging using PHP command-line switches
Launch PHP with the following command-line options:
php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_connect_back=0 path/to/script.phpphp -dxdebug.mode=debug -dxdebug.client_host=127.0.0.1 -dxdebug.client_port=9003 -dxdebug.start_with_request=yes path/to/script.php
Start the script with debugging using an environment variable
Set an environment variable that configures Xdebug:
For Windows:
set XDEBUG_CONFIG=remote_enable=1 remote_mode=req remote_host=127.0.0.1 remote_port=9000 remote_connect_back=0set XDEBUG_CONFIG=mode=debug client_host=127.0.0.1 client_port=9003 start_with_request=yesFor macOS / Linux
export XDEBUG_CONFIG='remote_enable=1 remote_mode=req remote_host=127.0.0.1 remote_port=9000 remote_connect_back=0'export XDEBUG_CONFIG='mode=debug client_host=127.0.0.1 client_port=9003 start_with_request=yes'
Start the script normally:
Optionally, you can use Xdebug's remote_autostart (for Xdebug 2) or start_with_request (for Xdebug 3) setting to always start a debugging session for every script that is run.
Starting the script with Zend Debugger
Zend Debugger has various configuration options which we can use to let the PHP interpreter reach out to PhpStorm. These parameters have to be passed to the PHP interpreter using an environment variable.
Start the script with debugging
Set the
QUERY_STRING
environment variable:set QUERY_STRING=start_debug=1&debug_host=127.0.0.1&no_remote=1&debug_port=10137&debug_stop=1export QUERY_STRING='start_debug=1&debug_host=127.0.0.1&no_remote=1&debug_port=10137&debug_stop=1'Start the script normally:
Optionally, to tell PhpStorm which path mapping configuration should be used for a connection from a certain machine, the value of the PHP_IDE_CONFIG
environment variable should be set to serverName=SomeName
, where SomeName
is the name of the server configured on the PHP | Servers page of the Settings/Preferences dialog Ctrl+Alt+S.
Xdebug.cli Color
If this environment variable is not set, you'll be prompted to specify path mappings manually once IDE detects an incoming Xdebug connection.
Debug
Xdebug Cli Disable
Once the script is started, PhpStorm will open the Debug tool window and break at the first breakpoint that was set in the script. You can now continue debugging a PHP CLI script as described in Examining a Suspended Program.
Xdebug Cli Not Working
If the script that is being debugged is not a part of the project that's open in PhpStorm, the IDE will still open the script in the editor and pause execution at the first statement. This makes it possible to quickly debug any PHP CLI script, even if there is no PhpStorm project for it yet.