It is possible to run PHP cli without a docker-compose file, I have found it is easier to set up PhpStorm using this intermediate step. PhpStorm has several preconfigured Docker containers, source: Github - JetBrains / phpstorm-docker-images; Docker hub - PhpStorm; They can be used as follows: Php 7.3 CLI and XDebug 2.7. 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. Now, to get Xdebug over the CLI to work we need to ensure a specific environment variable is present: PHPIDECONFIG. This contains the server name to be used, which PhpStorm maps to the configured servers for your project. An example value would be. Working for years with Drupal's command-line tool drush, and more recently with Laravel's artisan, I've had occasion to interface with Xdebug in my favorite IDE, PhpStorm. Here's how I am currently working with all of these tools together. Incidentally, if you've never tried a real debugger in your projects, you can check out my talk from WordCamp Orange County, 'Let's Debug for. Copying the xdebug config lines from the /etc/php5/apache2/php.ini file into /etc/php5/cli/php.ini setting an environment variable with the name of the debug session (you can get this from the query string in the url of the page netbeans launches when you start debugging) so the command is: export XDEBUGCONFIG='idekey=netbeans-xdebug'.
Phpstorm Xdebug Not Working
A quick guide to how to do this, since I always forget and have to look it up. This is done with docker4drupal, but should work equally well with any Docker Compose setup.
Enable xdebug on the relevant Docker container. For docker4drupal this means uncommenting these lines in the docker-compose.yml
file:
If you enable these after you've created the PHP container, remember to restart the container so that xdebug is enabled and configured.
Now go to Settings > Languages & Frameworks > PHP and set your language level as required. Add a new CLI interpreter by clicking ...
. Click the +
on the top left and add a new Docker configuration. Select Docker Compose and the php service, then use the default options for everything else. Save this and apply.
Next click the 'Add configuration' button on the taskbar in the top right. Pick the PHP Remote Debug template and click the +
on the top left to add a new configuration (don't make the mistake of editing the template). Check 'Filter debug connection by IDE key' and set the IDE key to match the one in your XDebug config (for the above we'd use PHPSTORM
). Add a server (the name doesn't matter). Give it the appropriate host and port—for docker4drupal the host will be something like http://myproject.docker.drupal.localhost, and the port will be 8000 unless you've changed it. Check 'Use path mappings', and set a path mapping for the root directory to /var/www/html
(or wherever it's mounted to on the container).
It's important to note that for this to work with Drush, or anything that exists both in Composer and globally, you need to invoke Drush from the binary in the vendor directory vendor/bin/drush
rather than using the system Drush, so that PHPStorm can use the path mappings. You could do this with a make command or Composer script. A make command I've used in the past:
This is a modified version of the default docker4drupal command.
ddev
Phpstorm Xdebug Vagrant
The process for ddev is largely the same. You can skip the step for setting up the CLI interpreter as this will work fine without it. An important point is that the name of your debug configuration must match your ddev site domain for this to work. See the ddev documentation for more details.
FeaturesYou may have noticed recent versions of the Composer dependency manager has come with a warning if you have Xdebug enabled:
Jordi added this warning because Xdebug does wondrous things when you are developing, but it slows down execution of PHP scripts massively. Turning Xdebug on and off depending on the situation can be a painful chore… Until now.
PhpStorm 2016.2 introduces Xdebug On Demand mode where you can disable Xdebug for your global PHP install, and PhpStorm will only enable it when it needs to — when you’re debugging your scripts, or when you need code coverage reports.
To use the great new feature, first, you need to disable Xdebug for command line PHP scripts. Usually, this is a case of either renaming a config file, or commenting out the lines that load the extension. While you’re working with the configuration that enables Xdebug in your actual PHP install, it’s worth taking a note of where the Xdebug extension lives on your system as you’ll need that later.
What you are looking for is when you run `php -v` from the command line, you don’t get the “with Xdebug by Derick Rethans” line:
Now we don’t have Xdebug installed, and our command line scripts (including Composer and our unit tests) will run much faster.
Next, we need to tell PhpStorm where to find Xdebug when we need it. To do this, navigate to Languages and Frameworks and then PHP in the preference pane. You’ll see a list of your configured interpreters in a drop down, pick the relevant PHP install and then press the … button to see it’s settings:
We just need to tell PhpStorm where to find the Xdebug extension in the Debugger extension field – that’s the location you should have taken note of earlier when you were looking at the config files. When you opened this screen, the Debugger information to the right of the PHP version said Not installed, but once you’ve set the debugger location, hitting the refresh icon above it will confirm that the extension is found and can be loaded; it will change to the version of Xdebug you are running.
Now we can debug as usual. If it’s a simple PHP script, then either use the Debug toolbar icon to start a debugging session (as usual), or if you don’t have a run configuration, right-click anywhere in the file, and select Debug and then the file name with the PHP file icon next to it. This will allow you to start a debug session right there without even running the debug session listener.
If you want to debug your PHP Unit tests, assuming you have a PHP Unit runner configured and you can debug your unit tests in the same way; by selecting the PHP Unit configuration from the drop-down in the menu bar, and then hitting the Debug button.
Making debugging easier and quicker is a definite goal in recent releases of PhpStorm, and personally, I think this solves a very annoying problem and speeds up execution of tests and other command-line scripts in the 90% use case; when you don’t need to debug or profile.
Phpstorm Xdebug Cli Vagrant
I hope you are excited as I am with this feature, give it a go and let me know what you think!
— Gary and the PhpStorm Team