Javascript required
Skip to content Skip to sidebar Skip to footer

Undo Do Not Show Again in Phpstorm

PHP Stride Debugging

Step-debugging with ddev and xdebug¶

Every ddev projection is automatically configured with xdebug and so that pop IDEs can do step-debugging of PHP code. It is disabled past default for performance reasons, and so you lot'll demand to enable it in your config.yaml.

xdebug is a server-side tool: It is installed automatically on the container and you do not need to install or configure it on your workstation.

All IDEs basically piece of work the same: They listen on a port and react when they're contacted at that place. IDEs other than those listed here work fine, if they listen on the default xdebug port 9003. (This was port 9000 through DDEV v1.18, changed to 9003 in v1.19+)

Fundamental facts:

  • Enable xdebug by running ddev xdebug or ddev xdebug on in your project directory. Information technology will remain enabled until you start or restart the project.
  • Disable xdebug for better functioning when not debugging with ddev xdebug off
  • ddev xdebug condition will show current condition.
  • The debug server port on the IDE must be fix to port 9003 (port 9000 earlier v1.xix), which is the default and is probably already set in most popular IDEs. (If you need to change the xdebug port due to a port conflict on your host calculator, you can do it with a PHP override, explained beneath.)

For more than groundwork on XDebug run into XDebug documentation. The intention here is that one won't have to empathize XDebug to do debugging.

For each IDE the link to their documentation is provided, and the skeleton steps required are listed here.

Setup for Various IDEs¶

  • PhpStorm
  • Visual Studio Lawmaking (vscode)
  • Cantlet

PhpStorm Debugging Setup¶

PhpStorm is a leading PHP development IDE with extensive built-in debugging support. It provides 2 unlike means to do debugging. One requires very trivial effort in the PhpStorm IDE (they telephone call it zero-configuration debugging) and the other requires you to prepare up a "run configuration", and is basically identical to the Netbeans or Eclipse setup.

If y'all are using PhpStorm inside WSL2 (or peradventure other Linux configurations), nether Help→ Edit Custom VM Options, add an boosted line: -Djava.internet.preferIPv4Stack=true This makes PhpStorm mind for Xdebug using IPV4; the Linux version of PhpStorm seems to default to using only IPV6.

PhpStorm Zero-Configuration Debugging¶

PhpStorm null-configuration debugging will automatically observe a connection and offer to create a "server", a file mapping from your workstation to the container. This means you only have to:

  1. Toggle the "Outset Listening for PHP Debug Connections" push:
    Start listening for debug connections button
  2. Set up a breakpoint.
  3. Visit a page that should stop in the breakpoint you set up.
  4. PhpStorm will ask you what mapping to use, so it tin figure out how to map the path inside the container to the path on your workstation. The first time you do this with a project, PhpStorm will pop upward a "server" dialog box to fix the mapping. The default will work, simply information technology's best to click the checkbox to map the whole project directory to /var/www/html.

Note when using this recommended option:

  1. Please apply the latest DDEV version.
  2. Under Run >> Edit Configurations, check that there are no "Servers" already defined. PhpStorm will create a new "Server" (file mapping) for y'all as discussed in a higher place, but only if you don't already have 1. You can delete all servers and have PhpStorm create a new one, or you can create/edit an existing server as discussed below.

PhpStorm "Run/Debug configuration" Debugging¶

PhpStorm run/debug configurations require slightly more up-front end piece of work but can offer more than flexibility and may be easier for some people.

  1. Nether the "Run" bill of fare select "Edit configurations"
  2. Click the "+" in the upper left and cull "PHP Web Application" to create a configuration. Give information technology a reasonable proper name.
  3. Create a "server" for the project. Brand sure that "Name" is exactly the aforementioned every bit your "host" (due east.m. my-site.ddev.site) (Screenshot below)
  4. Add file mappings for the files on the server. Click on the local repo path and add together "/var/www/html" as the "Absolute path on the server" and your repository root as the path on the host.
  5. Set an appropriate breakpoint.
  6. Start debugging by clicking the "debug" button, which will launch a page in your browser.

PhpStorm debug start

Server creation:

PhpStorm server creation

PhpStorm and Control-Line Debugging¶

If you need to debug control-line PHP processes, peculiarly code that is outside the docroot, the environment variable PHP_IDE_CONFIG is already set inside the web container, so you don't take to practise much more.

Even so, if you have not still used PhpStorm with xdebug for a regular web request, do that to automatically create the PhpStorm "server" with the same name as your principal URL (run into "Languages and Frameworks" -> "PHP" -> "Servers"). The fundamental job of the "server" is to map filesystem locations on the workstation (your figurer) to filesystem locations on the remote server (in this instance the ddev-webserver container). Often, PhpStorm has automatically ready a mapping that doesn't include the entire project (and then the vendor directory is not mapped, for instance). Then map the top-level directory of your project to /var/www/html in the container, as in this epitome:
PhpStorm mapping

Cantlet Debugging Setup¶

Atom is an extensible developers' editor promoted by GitHub. The bachelor extensions include php-debug which you can use to behave PHP debugging with the Xdebug PHP extension. This project is currently an alpha release.

  1. Under Preferences->+Install install the php-debug add-on:
    php-debug installation
  2. Add configuration to the Atom config.cson by choosing "Config..." under the "Atom" menu. A "php-debug" stanza must be added, with file mappings that chronicle to your project. Additionally, you lot will need to disable the debugger that comes with the atom-ide-ui parcel. (Example config.cson snippet
    Atom cson config
  3. Restart Atom to ensure new settings are loaded.
  4. Open a projection/folder and open a PHP file you'd like to debug.
  5. Ready a breakpoint. (Right-click->PHP Debug->Toggle breakpoint)
  6. Open the debug view and enable debugging by choosing Packages->PHP-Debug->Toggle Debugging. Y'all should encounter "Listening on address:port 127.0.0.1:9003".
  7. Visit a page that should trigger your breakpoint.

An example configuration:

                                                        "atom-ide-ui":     "cantlet-ide-debugger": {}     apply:       "atom-ide-debugger": "never"   "php-debug":     PathMaps: [       "remotepath;localpath"       "/var/world wide web/html;/Users/rfay/workspace/d8git"     ]                                  

Visual Studio Lawmaking (vscode) Debugging Setup¶

  1. Install the php-debug extension.
  2. Update the projection's [launch.json] (in .vscode/launch.json) to add "Listen for xdebug" (run across config snippet). For more than on launch.json, meet vscode docs.
  3. Prepare a breakpoint in your index.php. If it isn't solid red, restart.
  4. In the menu, cull Run->Beginning Debugging.You may take to select "Listen for XDebug" past the light-green arrowhead at the top left. The bottom pane of vscode should now be orangish (live) and should say "Listen for XDebug".
  5. Enable XDebug with ddev xdebug on
  6. In a browser, visit your project, you lot should hit the breakpoint.

Note that if you're using vscode on Windows with WSL2, you'll want the "PHP Debug" extension enabled in your distro (for example, Ubuntu). You'll also need the "Remote - WSL" extension enabled. vscode will suggest both of these to you if you have WSL2 enabled and a PHP project.

Using Xdebug on a Port Other than the Default¶

Past default, ddev is fix up to contact the default port, port 9003 on your IDE. Withal, if you have something else listening on that port or your IDE does non even so default to 9003, you'll need to change the port. (PhpStorm and vscode have switch to supporting 9003 instead of 9000 for some time now.)

  • To override the port, add an override file in the projection'southward .ddev/php directory. For instance, a file .ddev/php/xdebug_client_port.ini would change to use the traditional old port 9000:
                                                        [PHP]                    xdebug.client_port                    =                    9000                                  
  • And so change your IDE'south configuration to listen on the new port.

NOTE: If you are using a PHP version beneath PHP7.2, you will exist using Xdebug version 2.10, instead of 3.ten. In that case the port config should exist xdebug.remote_port instead.

Troubleshooting Xdebug¶

The basic thing to understand virtually xdebug is that it's a network protocol. Your IDE (similar PhpStorm) will listen on the xdebug port (9003 past default in v1.19+, previously 9000). And so if xdebug is enabled in the ddev spider web container with ddev xdebug on, then php inside the container will try to open a TCP connection to the IDE. Docker'south networking places the host-side listening IDE at host.docker.internal:9003. So you have to make sure that the network connexion is clear and can be made and everything should work. Here are basic steps to take to sort out any difficulty:

  • Think that the port in play is port 9003 for DDEV v1.19+, but before that it was port 9000.
  • Reboot your estimator.
  • Temporarily disable whatever firewall or VPN if you're having problem. Xdebug is a network protocol, and the php process inside the web container must exist able to establish a TCP connexion to the listening IDE (PhpStorm, for example).
  • Utilise ddev xdebug on to enable xdebug when you desire information technology, and ddev xdebug off when yous're washed with it.
  • Gear up a breakpoint at the first executable line of your alphabetize.php.
  • Tell your IDE to beginning listening. (PhpStorm: Click the phone push button, vscode: run the debugger.)
  • Utilise scroll or a browser to create a web request. For case, curl https://d9.ddev.site
  • If the IDE doesn't answer, take a wait at ddev logs. If y'all see a bulletin like ""PHP bulletin: Xdebug: [Step Debug] Could not connect to debugging customer. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port)" then php/xdebug (within the container) is non able to make a connection to port 9003.
  • ddev ssh into the spider web container. Can you telnet host.docker.internal 9003 and have it connect? If y'all can't, you lot might have an over-aggressive firewall. Disable it, or add a rule that would allow the connection to pass through. For case, on Debian/ Ubuntu that would be sudo ufw allow 9003/tcp.
  • In PhpStorm, disable the "listen for connections" button so it won't mind. Or just go out PhpStorm. With another IDE similar vscode, terminate the debugger from listening.
  • ddev ssh: Tin can telnet host.docker.internal 9003 connect? If information technology does, you have something else running on port 9003. On the host, utilise sudo lsof -i :9003 -sTCP:Heed to discover out what is at that place and terminate information technology, or change the xdebug port and configure PhpStorm to use the new i . Don't continue debugging until your telnet command does not connect. (Note that on Windows WSL2 you may take to look for listeners both inside WSL2 and on the Windows side.)
  • At present click the listen button on PhpStorm to start it listening for connections.
  • ddev ssh and try the telnet host.docker.internal 9003 again. Information technology should connect. If not, perchance PhpStorm is not listening, or non configured to listen on port 9003?
  • Bank check to make sure that Xdebug is enabled. You can use php -i | grep -i xdebug inside the container, or utilize whatever other technique you lot desire that gives the output of phpinfo(), including Drupal's admin/reports/condition/php. Y'all should see with Xdebug v3 and php -i | grep xdebug.mode should requite yous xdebug.mode => debug,develop => debug,develop".
  • Ready a breakpoint in the first relevant line of the index.php of your project and so visit the site in a browser. It should cease at that first line.
  • If you are using PhpStorm within WSL2 (or mayhap other Linux configurations), under Help→ Edit Custom VM Options, add an additional line: -Djava.cyberspace.preferIPv4Stack=truthful This makes PhpStorm listen for Xdebug using IPV4; the Linux version of PhpStorm seems to default to using simply IPV6.
  • If you lot are on WSL2 using Docker Desktop, make sure that the docker command is the one provided by Docker Desktop. ls -50 $(which docker) should evidence a link to /mnt/wsl/docker-desktop.... If you lot are on WSL2 using docker installed inside WSL2, brand sure that ls -l $(which docker) is not a link to /mnt/wsl.

Final update: 2022-04-06

arabanoosuraces1945.blogspot.com

Source: https://ddev.readthedocs.io/en/stable/users/step-debugging/