Xdebug is an extension for debugging your PHP. Although you can use an IDE of your choice, the following explains how to configure Xdebug and PhpStorm to debug in your local environment.
You can configure Xdebug to run in the Cloud Docker environment for local debugging without changing your Adobe Commerce on cloud infrastructure project configuration. See Configure Xdebug for Docker.
To enable Xdebug, you must configure a file in your Git repository, configure your IDE, and set up port forwarding. You can configure some settings in the
magento.app.yaml file. After editing, push the Git changes across all Starter environments and Pro Integration environments to enable Xdebug. Xdebug is already available in Pro Staging & Production environments.
Once configured, you can debug CLI commands, web requests, and code. Remember that all cloud infrastructure environments are read-only. Clone the code to your local development environment to perform debugging. For Pro Staging and Production environments, see additional instructions for Xdebug.
To run and use Xdebug, you need the SSH URL for the environment. You can locate the information through the Project Web Interface or your Cloud Onboarding UI.
To configure Xdebug, follow these steps:
To add Xdebug, Adobe recommends working in a development branch.
You can enable Xdebug directly to all Starter environments and Pro Integration environments. This configuration step is not required for Pro Production & Staging environments. See Debug for Pro Staging and Production.
To enable Xdebug for your project, add
xdebug to the
runtime:extensions section of the
To enable Xdebug:
In your local terminal, open the
.magento.app.yaml file in a text editor.
runtime section, under
xdebug. For example:
runtime: extensions: - redis - xsl - newrelic - sodium - xdebug
Save your changes to the
.magento.app.yaml file and exit the text editor.
Add, commit, and push the changes to redeploy the environment.
git add -A
git commit -m "Add xdebug"
git push origin <environment-ID>
When deployed to Starter environments and Pro Integration environments, Xdebug is now available. Continue configuring your IDE. For PhpStorm, see Configure PhpStorm.
The PhpStorm IDE must be configured to properly work with Xdebug.
To configure PhpStorm to work with Xdebug:
In your PhpStorm project, open the Settings panel.
In the Settings panel, expand and locate the Languages & Frameworks > PHP > Servers section.
Click the + to add a server configuration. The project name is in gray at the top.
[Optional] Configure the following settings for the new server configuration. See No debug server configured in the PHPStorm documentation.
PHP_IDE_CONFIGvariable in Debug CLI commands to use CLI for debugging.
Select Use path mappings. In the File/Directory pane, the root of the project for the
In the Absolute path on the server column, click the Edit icon and add a setting based on the environment.
For all Starter environments and Pro Integration environments, the remote path is
For Pro Staging and Production environments:
Change the Xdebug port to 9000 in the Languages & Frameworks > PHP > Debug > Xdebug > Debug Port panel.
XDEBUG connection from the server to your local system. To do any type of debugging, you must forward port 9000 from your Adobe Commerce on cloud infrastructure server to your local machine. See one of the following sections:
To set up port forwarding on a Mac or in a UNIX® environment:
Open a terminal.
Use SSH to establish the connection.
ssh -R 9000:localhost:9000 <ssh url>
-v (verbose) option so that whenever a socket is connected to the port that is being forwarded it shows in the terminal.
If an “unable to connect” or “could not listen to port on remote” error is displayed, there could be another active SSH session persisting on the server that is occupying port 9000. If that connection is not being used, you can terminate it.
To troubleshoot the connection:
Use SSH to log in to the remote Integration, Staging, or Production environment.
View a list of SSH sessions:
View existing SSH sessions by user. Be careful to not affect a user other than yourself!
For a user session that is older than yours, find the pseudo-terminal (PTS) value, such as
Kill the process ID (PID) corresponding to the PTS value.
ps aux | grep ssh kill <PID>
dd2q5ct7mhgus 5504 0.0 0.0 82612 3664 ? S 18:45 0:00 sshd: dd2q5ct7mhgus@pts/0
To terminate the connection, enter a kill command with the process ID (PID).
To set up port forwarding (SSH tunneling) on Windows, you must configure your Windows terminal application. This example steps through creating an SSH tunnel using Putty. You can use other applications such as Cygwin. For more information on other applications, see the vendor documentation provided with those applications.
To set up an SSH tunnel on Windows using Putty:
If you have not already done so, download Putty.
In the Category pane, click Session.
Enter the following information:
In the Category pane, click Connection > SSH > Tunnels.
Enter the following information:
In the Category pane, click Session.
In the Saved Sessions field, enter a name for this SSH tunnel.
To test the SSH tunnel, click Load, then click Open.
If an “unable to connect” error displays, verify the following:
For initiating debugging, performing setup, and more, you need the SSH commands for accessing the environments. You can get this information, through the Project Web Interface and your project spreadsheet.
For Starter environments and Pro Integration environments, you can use the following
magento-cloud CLI command to SSH into those environments:
magento-cloud environment:ssh --pipe -e <environment-ID>
To use Xdebug, SSH to the environment as follows:
ssh -R <xdebug listen port>:<host>:<xdebug listen port> <SSH-URL>
ssh -R 9000:localhost:9000 pwga8A0bhuk7oemail@example.com
On Pro Staging & Production environments, Xdebug is always available as these environments have a special setup for Xdebug. All normal web requests are routed to a dedicated PHP process that does not have Xdebug. Therefore, these requests are processed normally and are not subject to the performance degradation when Xdebug is loaded. When a web request is sent that has the Xdebug key, it is routed to a separate PHP process that has Xdebug loaded.
To use Xdebug specifically on Pro plan Staging and Production environment, you create a separate SSH tunnel and web session only you have access to. This usage differs from typical access, only providing access to you and not to all users.
You need the following:
SSH commands for accessing the environments. You can get this information, through the Project Web Interface or your Cloud Onboarding UI.
xdebug_key value set when configuring the Staging and Pro environments.
xdebug_key can be found by using SSH to log in to the primary node and executing:
cat /etc/platform/*/nginx.conf | grep xdebug.sock | head -n1
To set up an SSH tunnel to a Staging or Production environment:
Open a terminal.
Clean up all SSH sessions for each web node of the cluster.
ssh USERNAME@CLUSTER.ent.magento.cloud 'rm /run/platform/USERNAME/xdebug.sock'
Set up the SSH tunnel for Xdebug for each web node of the cluster.
ssh -R /run/platform/USERNAME/xdebug.sock:localhost:9000 -N USERNAME@CLUSTER.ent.magento.cloud
To start debugging using the environment URL:
Enable remote debugging; visit the site in the browser and append the following to the URL where
KEY is value for
This step sets the cookie that sends browser requests to trigger Xdebug.
Complete your debugging with Xdebug.
When you are ready to end the session, use the following command to remove the cookie and end debugging through the browser where
KEY is value for
XDEBUG_SESSION_START passed by
POST requests are not supported.
This section walks through debugging CLI commands.
To debug CLI commands:
SSH into the server you want to debug using CLI commands.
Create the following environment variables:
export PHP_IDE_CONFIG="serverName=<name of the server that is configured in PHPSTORM>"
These variables are removed when the SSH session ends.
On Starter environments and Pro Integration environments, run the CLI command to debug.
You may add runtime options, for example:
php -d xdebug.profiler_enable=On -d xdebug.max_nesting_level=9999 bin/magento cache:clean
On Pro Staging and Production environments, you must specify the path to the Xdebug PHP configuration file when debugging CLI commands, for example:
php -c /etc/platform/USERNAME/php.xdebug.ini bin/magento cache:clean
The following steps help you debug web requests.
On the Extension menu, click Debug to enable.
Right click, select the options menu, and set the IDE key to PHPSTORM.
Install the Xdebug client on the browser. Configure and enable it.
This section discusses how to use Xdebug in Chrome using the Xdebug Helper extension. For information about Xdebug tools for other browsers, consult the browser documentation.
To use Xdebug Helper with Chrome:
Create an SSH tunnel to the Cloud server.
Install the Xdebug Helper extension from the Chrome store.
Enable the extension in Chrome as shown in the following figure.
In Chrome, right-click the green helper icon in the Chrome toolbar.
From the pop-up menu, click Options.
From the IDE Key list, click PhpStorm.
Open your PhpStorm project.
In the top navigation bar, click the Start listening icon.
If the navigation bar is not displayed, click View > Navigation Bar.
In the PhpStorm navigation pane, double-click the PHP file to test.
Because of the read-only environments, you must pull code to the local workstation from an environment or specific Git branch to perform debugging.
The method you choose is up to you. You have the following options:
Check out code from Git and run
This method works unless
composer.json references packages in private repositories to which you do not have access. This method results in getting the entire Adobe Commerce codebase.
This method results in your having all code you can possibly test. Depending on how many static assets you have, it could result in a long transfer with a large volume of files.
vendor directory only
Because most of the code is in the
vendor directory, this method is likely to result in good testing, although are not testing the entire codebase.
To compress files and copy them to your local machine:
Use SSH to log in to the remote environment.
Compress the files.
tar -czf /tmp/<file-name>.tgz <directory list>
For example, to compress the
vendor directory only:
tar -czf /tmp/vendor.tgz vendor
On your local environment, use PhpStorm to compress the files.
cd <phpstorm project root dir>
rsync <SSH-URL>:/tmp/<file-name>.tgz .
tar xzf <file-name>.tgz