Xdebug For Phpstorm



This video is a part of JetBrains PhpStorm Video Tutorials by JetBrains Technical Evangelist Maarten Balliauw.

  1. Configure Xdebug For Phpstorm
  2. Phpstorm Xdebug Docker Cli
  3. Phpstorm Xdebug Not Working
  1. Turn on XDebug inside the VM; Start listening for connections in PhpStorm by clicking the small telephone icon; Load a VM page in your browser PhpStorm will detect a request to connect, but will complain that path mappings are not set up. This is fine, we’re about to do that.
  2. XDebug Remote Debugging So the idea is to write PHP code in PHPStorm on Windows and run and debug PHP code on Ubuntu over WSL2. To do that, we need to setup remote debugging for XDebug so that PHPStorm can connect to it and set breakpoints, show variable values and step through the code.
  3. Xdebug: A powerful debugger for PHP. This setting controls which Xdebug features are enabled. This setting can only be set in php.ini or files like 99-xdebug.ini that are read when a PHP process starts (directly, or through php-fpm), but not in.htaccess and.user.ini files, which are read per-request. The following values are accepted.
  4. It looks like PhpStorm's checking script isn't fully updated yet, so it's recommending a confusing mixture of old and new settings. The most important changes are: The new xdebug.mode setting toggles a whole bunch of settings at once rather than having to remember the right combination. Some settings are simply no longer needed because of this.

This article will show you step by step how to install and use Xdebug on Windows.

Contents:

Resources:

Official Xdebug installation guide from JetBrains (really good)

What is Xdebug?

Xdebug is an extension for PHP to assist with debugging and development.

Phpstorm

Why use Xdebug?

Resident evil jill eye color. Makes development easier by allowing the developer to debug his code in a simple and quick way.

How to install Xdebug

In this tutorial, we will be installing Xdebug on Windows 10, the steps are similar for any Windows version. You must have PHP installed on your system.

  1. Go here and install Xdebug:
                1. Run the following command in a terminal:
                2. Copy the output of that command and paste it in the Xdebug Wizard. Then click Analyze my phpinfo() output.
                3. Once analyzed, the result will tell if you have Xdebug installed or not, and which .dll file to download.
                4. Download the specified file from the step before. For me is: php_xdebug-2.6.0-7.2-vc15-nts-x86_64.dll
                5. Move the downloaded file to the /ext folder. This is the folder where PHP keeps all of its extensions and can be found under the folder where you have installed PHP. On mine, it is located in C:PHPext.
                6. Copy file to ext directory

                7. Open php.ini file in an editor like Notepad, Notepad++ or Visual Code. This file is located within the folder where you installed PHP, C:PHPphp.ini for me.
                8. At the end of this file, add the following lines:
                9. Check if Xdebug has been installed by running the following command in a terminal:

                  The line that says ‘with Xdebug v2.7.0alpha1’ confirms that it has been installed correctly. Calibre epub review.

The basic idea in PhpStorm is that you tell it where to look for the xdebug session (the “server”) and then you tell it how to link the files it’s running in the VM to the files found in the repo (called “mapping”).

For

What follows are opinionated defaults, so adjust as you deem necessary. Specifically, the PHP versions you’ll be supporting

XdebugConfigure

Confirm PhpStorm’s project setup

Make sure you have your project folders already set up in phpStorm.

Configure Xdebug For Phpstorm

  1. Open preferences in the main menu, and navigate to the Directories section
  2. Make sure your project’s content root is set
  3. Click Languages & Frameworks, PHP and fill it in like this
    • Set the PHP language level to match the site you’re debugging.
    • CLI Interpreter: select one if you have it, leave it as <no interpreter> if you don’t
    • Include Path section: add the path to the locally-mapped public_html folder of the VM for your project

Phpstorm Xdebug Docker Cli

Set up the Server

This is not a server in the sense of an actual server, more like the settings on how to connect to the VVV server already set up.

  1. In the default toolbar, you’ll see a select box that has either “Add Configuration…” (if you haven’t set up debugging for another project) or “Edit configurations…” (if you have). Whatever it says, click it.
    • If you don’t see this item in your toolbar, add it in by customizing the toolbar. You’ll thank me later.
  2. Click the + sign top left and select PHP Remote Debug and fill it in using the following settings:
    • Name: <your project name> Debug
    • Filter debug connection by IDE key: enabled
    • Server: skip for now
    • IDE Key: VVVDEBUG
  3. Click Apply and keep clicking Apply until you’re back in the editor.

Set up the Folder Mapping

For PhpStorm and xdebug to correctly hit breakpoints and talk to each other, we need to tell PhpStorm how the files it knows about are mapped to the files that VVV knows about.

There is a way to get the server going manually but there is an easier way: get PhpStorm to do the important bits for us. Here’s how.

  1. Start listening for connections in PhpStorm by clicking the small telephone icon
  2. Load a VM page in your browser
    • PhpStorm will detect a request to connect, but will complain that path mappings are not set up. This is fine, we’re about to do that. But what PhpStorm also does is set up the “Server” configuration for us. Sweet!
  3. When you see the “Incoming Connection from Xdebug” window, click “Manually choose local file or project” and then “Accept”
    • At this point, debugging will run and then stop because the mappings are not set up yet, and there are no break points. Time to fix that.
  4. In the toolbar, select “Edit Configurations…”
  5. On the left side make sure the “ Debug' config is selected, then click the ellipsis in the 'Server:' section
  6. Look at the server already set up for us. Thanks PhpStorm. Now to do the mapping.
    • The key to remember here is that we are mapping the files from where they are relative to the mapped server folder, to where they are in the code repo as it is linked within the VM.
  7. Enable “Use path mappings….” to enable the section below it.
  8. Expand “Project files” and then expand the project path.
  9. Fill in the highest-level section you can to capture everything. For simple projects this will likely be a 1:1 mapping, but for complicated nested projects you may not have to map absolutely eveything, only the children
  10. Expand “Include Path”
  11. Fill in the items below, and only the items below, into this section (if it’s not already filled in; it should be):

Phpstorm Xdebug Not Working

File/ DirectoryAbsolute path on server
/path/to/vm/www/<project>/public_html/srv/www/path/to/mapped/folder
  1. Click Apply until you’re back at your code view.

Done. Now once you enable Xdebug, turn on debugging in PhpStorm and set a breakpoint, you’re ready to debug.