Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #184 from craftcms/feature/xdebug-setup-edits
Browse files Browse the repository at this point in the history
Spiff up Xdebug PhpStorm setup instructions.
  • Loading branch information
jasonmccallister authored Jul 17, 2020
2 parents 2777e10 + f358a46 commit 7203119
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions XDEBUG.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
# Using Xdebug with Nitro and PhpStorm

Once you have a machine created, you can run `nitro xdebug on` and `nitro xdebug configure` to enable Xdebug and set it up for automatic remote connections from your host machine. These make the
Once you’ve created a machine, you can run `nitro xdebug on` and `nitro xdebug configure` to enable [Xdebug](https://xdebug.org/) and set it up for automatic connections from your host machine.

## Debugging web requests
You can use `nitro xdebug off` to disable Xdebug without having to restart the machine.

Install the Xdebug browser helper in your favorite browser.
## Configuring PhpStorm

- [Chrome](https://chrome.google.com/extensions/detail/eadndfjplgieldjbigjakmdgkmoaaaoc)
- [Firefox](https://addons.mozilla.org/en-US/firefox/addon/xdebug-helper-for-firefox/)
- [Internet Explorer](https://www.jetbrains.com/phpstorm/marklets/)
- [Safari](https://github.com/benmatselby/xdebug-toggler)
- [Opera](https://addons.opera.com/addons/extensions/details/xdebug-launcher/)

Go to the Xdebug browser helper options, choose "PhpStorm" and save.

![Xdebug Browser Helper Chrome](resources/xdebug_chrome_settings.png)

Create a new server in PhpStorm using your machine's domain name.
First, you’ll need to configure PhpStorm to listen for requests from the browser or console.

1. Create a new server in PhpStorm using your machine’s domain name. (“Preferences” → “Languages & Frameworks” → “PHP” → “Servers”.)
![PhpStorm Server Settings](resources/phpstorm_server.png)

Setup path mappings to that `/app/sites/example.test` in your Nitro machine is
mapped to your project's root on your host machine.
2. Enable “Use path mappings” and set your existing project root to the absolute path on the server. The absolute path will look like `/home/ubuntu/sites/my-site`, where `my-site` reflects your actual project’s folder name in the Nitro machine. (Use `nitro context` if you need to check the path, and keep in mind this is the project root and not necessarily the web root.)

Create a new "PHP Remote Debug" configuration and select the server you just created.
3. Choose “Run” → “Edit Configurations...” and create a new “PHP Remote Debug” configuration, selecting the server you just created. Check “Filter debug connection by IDE key” and enter `PHPSTORM`.
![PhpStorm Remote Debug Settings](resources/phpstorm_remote_debug.png)

Check "Filter debug connection by IDE key" and enter "PHPSTORM" for the IDE key.
4. Choose “Run” → “Start Listening for PHP Debug Connections”.
![PhpStorm Remote Debug Settings](resources/start_listening.png)

![PhpStorm Remote Debug Settings](resources/phpstorm_remote_debug.png)
## Debugging Web Requests

Click the "Start Listening for PHP Debug Connections" button in PhpStorm.
1. Install the Xdebug helper in your favorite browser.

![PhpStorm Remote Debug Settings](resources/start_listening.png)
- [Chrome](https://chrome.google.com/extensions/detail/eadndfjplgieldjbigjakmdgkmoaaaoc)
- [Firefox](https://addons.mozilla.org/en-US/firefox/addon/xdebug-helper-for-firefox/)
- [Internet Explorer](https://www.jetbrains.com/phpstorm/marklets/)
- [Safari](https://github.com/benmatselby/xdebug-toggler)
- [Opera](https://addons.opera.com/addons/extensions/details/xdebug-launcher/)

Click the "Debug" button on your browser's Xdebug helper.
2. In the browser helper’s options, choose “PhpStorm” and save.
![Xdebug Browser Helper Chrome](resources/xdebug_chrome_settings.png)

3. Choose “Debug” on your browser’s Xdebug helper.
![PhpStorm Remote Debug Settings](resources/xdebug_chrome.png)

Then load the site in your browser and whatever breakpoints you've set will be hit.
4. Load the site in your browser and whatever breakpoints youve set will be hit.

## Debugging PHP console requests
## Debugging Console Requests

Do everything above except Xdebug browser helper. SSH into your Nitro machine using
`nitro ssh`, then run your PHP script from the console and any breakpoints you've
set will be hit.
SSH into your Nitro machine using `nitro ssh`, then run your PHP script from the console and any breakpoints you’ve set will be hit.

0 comments on commit 7203119

Please # to comment.