-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wp-env: Xdebug support #27346
wp-env: Xdebug support #27346
Conversation
packages/env/lib/init-config.js
Outdated
@@ -55,3 +64,18 @@ module.exports = async function initConfig( { spinner, debug } ) { | |||
|
|||
return config; | |||
}; | |||
|
|||
function dockerFileContents( image, xDebugMode ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's helpful to have our own Dockerfile at this point. I imagine this could open up the path to some other features too.
Size Change: 0 B Total Size: 1.21 MB ℹ️ View Unchanged
|
That's not true. IDEs continue to support Xdebug 3 just as they support Xdebug 2. The only change is that Xdebug's settings are different, and that the default port changed from 9000 to 9003 so that it does not conflict with PHP-FPM any more. Upgrade guide → https://xdebug.org/docs/upgrade_guide |
Alright, I will try again then. I did update the local settings to match the new version but had no luck getting it to connect. It looks like folks have had some success here since I looked into it: xdebug/vscode-php-debug#411 |
9528563
to
4d441d4
Compare
@derickr Thanks for reminding me to look a little more closely! I was able to get it working. I think the problem was that |
Yes, |
be5c2d0
to
bdbdbfc
Compare
The debugging itself works wonderfully for me 🎉 Reviewing the code now |
The only reason I can think of not to include the file is to avoid cluttering the root for people who don't use xdebug, but adding it makes sense to me. |
Hmmm...had this working great earlier. Realized the HEAD of my local branch was outdated, and pulled the latest changes. Now xdebug won't recognize breakpoints anymore 🤔 I've tried cleaning the WordPress instance, destroying the docker volumes and starting over, and restarting my computer. No luck yet. |
I think I can reproduce the issue:
Running a subsequent Debugging on my end shows that, for some odd reason, |
This might be a local development issue -- let me know if you're able to reproduce the problem @noahtallen . If not, I'll keep trying to dig around and fix the issue on my mac. |
I'll look into that, it definitely sounds like a bug. BTW, some wp-env tips that might be useful for your use case!
You can replace that command with
You can also run this directly: Might be more ergonomic to use than using the container ID ;) |
Thanks for those! I'll add them to my notes 😃 |
This makes total sense to me as well. 👍 I'm not as familiar with all the use cases, but in my day-to-day workflow, I don't imagine this affecting my dev process either. I'm on board with this solution. Side note -- do you think it would be overkill to add a note in the docs? I can't imagine these changes causing a problem in the future, but I've been wrong in the past 😛 |
yep :) I think the only use case I can think of is running something like |
Testing the changes now. Will update this comment as I progress.
|
I noticed that For example:
Is this expected? +1 whenever we resolve this conversation 🙂 |
Hmm, that is unexpected, but I understand what is happening. I don't think Docker rebuilds the image unless the update flag is passed, which means the commands won't get set. I think I have a fix. |
Nice! Thanks for working on this Noah. Installing and setting up xdebug in this environment feels so easy ⭐️ |
Fixed in dad241a.
Thanks! |
Ahhh so close. So the config files are all updating properly, but now the debugger no longer works. It's not recognizing my breakpoints. I saw that you removed the |
Not that I know of, other than running |
@jeyip it's working for me. Here's my launch.json in whole:
the part in the PR description is just an individual entry |
Yeah that's what I had as well. Not sure why it wasn't catching, but I restarted my terminal / editor and it works now 🤷♂️ Aaaaannnnd let's ! |
Woohoo! 🎉 Any change this can be updated on the npm package? I'd love to use xdebug on my own project. |
Unfortunately, wp-env has to be updated along with the rest of the npm packages in the monorepo, which hasn’t happened since before the latest WordPress release cycle. So I expect we can get a new version out in the next few weeks |
Ah, okay no problem. Thanks for the reply! |
@ajgagnon you can install the module yourself until it's out:
Now the instance of wp-env that you run will be what you installed from your local filesystem. Just remember to uninstall that one and install the official again once another version ships. This was too valuable a feature to wait on though... |
Description
Installs Xdebug 3 in the wp-env WordPress service.
How has this been tested?
It should work, but I can't test it since my IDE can't connect to it.
Setup environment
npx wp-env start --update --xdebug
to rebuild the docker image with Xdebug (and to enable xdebug)IDE setup
This will depend on your IDE. look for the PHP debug function (or extension) in your IDE, and make sure the key settings like "port" and "pathMappings" match the settings given for VS Code.
4. Set a breakpoint in a PHP file like `lib/load.php` and refresh your browser at `localhost:8888` 5. Breakpoint should trigger:
Public API:
Xdebug will be installed for all wp-env users by default, but set to the "off" mode, which adds zero overhead. To enable basic debugging with xdebug, simply run
npx wp-env start --xdebug
. Beyond that, you can set any Xdebug mode like so:npx wp-env start --xdebug=trace,gcstats
.Other considerations:
Should we include the launch.json file in the repository?