I've found a more modern and easier solution partially based on CrasyCoder's post. The steps you need to do are the following:
- If your brand new php installation doesn't contain php.ini, rename the php.ini-development to php.ini
- Install xdebug with help of the wizard: http://xdebug.org/wizard.php Follow its recommendations literally.
- Put in your php.ini the string: xdebug.remote_enable=1
- Go to PhpStorm's settings: settings->php. Select or reselect directory containing php. Make sure you see 'Debugger: Xdebug x.x.x' string (where x.x.x stands for installed version)
- Install an extension for your favorite browser from here: http://xdebug.org/docs/remote
- From the main menu (not the settings window) go to 'Run->Edit configurations' and add new 'PHP Built-in Web Server' configuration. Point the 'Document root' to your project's directory. Note the port number.
- Chrome browser: enable the extension pressing on the little bug in the rightmost side of the omnibox and selecting the Debug option. Other browsers' extensions should work similarly.
- In PhpStorm's menu enable the 'Run -> Start Listen for PHP Debug connections' option.
- Set a breakpoint in your code in PhpStorm.
- Run (not debug) the configuration you created in step 6.
- In your browser go to localhost:port where 'port' is the port from step 6. Your PhpStorm should stop on the breakpoint and you can start squashing bugs in your code.
Considering that:
Steps 1-5 are made once per php installation.
Step 6 is made once per PhpStorm project.
Steps 7-8 are made once per debuggin session.
Steps 9-11 are made each program run.
I've found a more modern and easier solution partially based on CrasyCoder's post. The steps you need to do are the following:
- If your brand new php installation doesn't contain php.ini, rename the php.ini-development to php.ini
- Install xdebug with help of the wizard: http://xdebug.org/wizard.php Follow its recommendations literally.
- Put in your php.ini the string: xdebug.remote_enable=1
- Go to PhpStorm's settings: settings->php. Select or reselect directory containing php. Make sure you see 'Debugger: Xdebug x.x.x' string (where x.x.x stands for installed version)
- Install an extension for your favorite browser from here: http://xdebug.org/docs/remote
- From the main menu (not the settings window) go to 'Run->Edit configurations' and add new 'PHP Built-in Web Server' configuration. Point the 'Document root' to your project's directory. Note the port number.
- Chrome browser: enable the extension pressing on the little bug in the rightmost side of the omnibox and selecting the Debug option. Other browsers' extensions should work similarly.
- In PhpStorm's menu enable the 'Run -> Start Listen for PHP Debug connections' option.
- Set a breakpoint in your code in PhpStorm.
- Run (not debug) the configuration you created in step 6.
- In your browser go to localhost:port where 'port' is the port from step 6. Your PhpStorm should stop on the breakpoint and you can start squashing bugs in your code.
Considering that:
Steps 1-5 are made once per php installation.
Step 6 is made once per PhpStorm project.
Steps 7-8 are made once per debuggin session.
Steps 9-11 are made each program run.
It's really simple to get Xdebug working with PhpStorm, just follow this guide carefully. (NOTE: Updated version of the guide is here)
For more advanced topics read this.
Beginner instructions for PHPStorm + XDebug + (XAMPP or Local) needed...
php - How do I install and configure Xdebug/PhpStorm - Stack Overflow
How to use xDebug with Symfony?
Best way to use PHPStorm with WSL2
Well VSCode offers remote development: https://code.visualstudio.com/docs/remote/remote-overview
And Jetbrains followed suit: https://blog.jetbrains.com/blog/2021/11/29/introducing-remote-development-for-jetbrains-ides/
More on reddit.comVideos
I have been trying for 2 days to get PHPStorm to work with XDebug and either XAMPP or Local and I just cannot seem to figure it out.
Here's what I would like to do.....
I have a WordPress site that needs some minimal changes to some API calls. I have no problem writing that code. I've written it in plugins and it's running fine. But I wrote that "blind" - as in I just wrote the code in a text editor and uploaded it and it works.
I want to be able to do more serious debugging with a tool like PHPStorm so I can step through the code on the site that I didn't write (and don't completely understand) to learn what it does and possibly fix some PHP errors that I see popping up.
I backed up the production site using UpdraftPlus, downloaded the backup files and restored the production site to a local dev site in XAMPP and I also did the same thing to a local dev site in Local.
Both sites work just like the production site (just a bit slower than the production site running on a Cloudways virtual server). The XAMPP site runs 2 to 6 times faster than the Local site, depending on what you are doing (uploading files or just surfing the site, etc.).
It is at that point that I am failing to do what I need to do. Here is what I need to be able to do....
Load either site into PHPStorm
Open a file in PHPStorm and set a breakpoint
Open a browser and go to the page/button/whatever that triggers the code
Have the code stop at the breakpoint in PHPStorm for inspection/changes
Be able to step through the code from the breakpoint forward, learning what the code is doing
I'd like to use PHPStorm for this, but getting it all set up is like some cruel joke. I've seen examples of people setting up CLI servers, actual servers, assigning PHP executables, etc. in YouTube video after video. Most of the videos are 2 to 10 years old and you might get half done or even 75% done when their UI no longer looks like yours and finding the settings they are tweaking is nigh impossible. Even if you find something that looks similar it's never exactly the same and there are more fields to fill out with no clue what goes in them.
Then there are several different ways that I've seen the php.ini files and Apache settings done. Which is right? Which is best? Who knows? Not me....that's for sure.
Worse yet is the lost feeling when I cannot figure out just how they know even the parts that I can follow along with. I cannot, for the life of me, find a simple "Step 1, Step 2, Step 3...." that is current and works to set this stuff up.
There doesn't seem to be an "Absolute Idiot's Guide to PHP Debugging with PHPStorm and XAMPP" - which is what I think I need at this point.
And it is odd to me that there is no checklist or walk-through plug-in in PHPStorm or VS Code that asks you questions and sets up the environment based on your answers. There isn't even a written checklist that is current and workable that I can find.
It isn't all the fault of the tools (if any at all) though.....I am a full time caregiver for my mother who has Parkinson's. When not doing that I try and care for our dog who has congestive heart failure. When I can get away from those duties I have to maintain the home. And then I need to work - something I try to do from home as much as humanly possible because there is nobody to stay with my mother (who has fallen on occasion and needs someone nearby). The only undisturbed time I have to study any of this is when they are asleep (and I should be sleeping). So it is entirely possible that I am just worn completely out and cannot see the forest for the trees.
Be that as it may, I still am desperate to get this job done. I have 3 weeks to do it and if I can't get this unholy trio of PHPStorm/VS Code, XAMPP/Local and Xdebug to somehow come together into something useful, I don't see how I will make that deadline.
It isn't for lack of looking that I haven't figured it out....I've watched/read over 70 videos/articles and so far they all fail to produce the desired result.