Issues connecting Vagrant Xdebug with PhpStorm 2020.3 - vagrant

Have spent over a day trying to get PhpStorm to debug a Drupal site inside a Vagrant virtual machine running Xdebug and I feel I'm close - but just not quite there yet.
Currently, in PhpStorm when debugging I have an error:
Waiting for incoming connection with ide key 'PHPSTORM'
In the Xdebug log in the VM (at /tmp/xdebug.log)
[2094] I: Checking remote connect back address.
[2094] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[2094] I: Checking header 'REMOTE_ADDR'.
[2094] I: Remote address found, connecting to 192.168.88.1:9000.
[2161] E: Time-out connecting to client (Waited: 200 ms). :-(
[2161] Log closed at 2020-12-15 04:25:32
I tried setting up the Zero-configuration debugging without any luck.
For the debugging configuration, I have a PHP Remote Debug that validates correctly although it always defaults to the 'Local Web Server or Shared Folder' rather than the 'Remote Web Server' option.
When I started the project I set it up as a local web server option and I'm worried that I haven't changed the correct settings to now make this a remote web server. The connection type for the deployment is now 'Local or mounted folder' but originally this was 'In-place'.
Under Languages & Frameworks --> PHP --> Servers, I set this up on port 80, using Xdebug and without path mappings. I tried changing the port etc but then it doesn't validate so I'm confident that the server settings are correct and that PhpStorm is talking to the virtual machine correctly.
I changed the /etc/php/7.4/cli/php.ini file but phpinfo() says the configuration is coming from /etc/php/7.4/fpm/php.ini. The changes I made in the php.ini file are active though. phpinfo() is showing:
xdebug.idekey: PHPSTORM
xdebug.remote_host: 10.0.2.2
xdebug.remote_port: 9000
xdebug.remote_autostart: Off
xdebug.remote_connect_back: On
Really at a loss now as to what to try next. It is incredibly frustrating so hope someone can shed some light.
EDIT --- As per comment here is the screenshots of the setup:
Deployment: Local or mounted folder
PHP settings
The server setup
Debug settings
Validate the debugger from the remote server
Run Chrome with the debug addon running
The error message
The Run debug configuration settings
Start of the phpinfo with the config file showing where the xdebug settings need to be edited.
The Xdebug settings of phpinfo()
Some of the tests as per the comments:
After logging in to 'vagrant SSH' it shows the IP address to be used (10.0.2.2). The local computer is also IP 10.1.1.150 a telnet test of both of these works.
A 'sudo nano' of the Xdebug ini file
NOTE: Changing the remote connect back to 0 fixed the connection:
xdebug.remote_connect_back=0
And then the path mapping needed to be turned on in the Server settings and then everything was working correctly.
Big thanks to LazyOne for his helpful and thorough comments. :)

1) Check if there are separate php.ini files used by web server, -- you need to edit the right php.ini file.
Run phpinfo() and check to see if there is an ini file for Xdebug. In my case this was at /etc/php/7.4/fpm/conf.d/20-xdebug.ini
2) What's your Xdebug version?
Version 2 and 3 of Xdebug have slightly different parameters. In my case I was running Xdebug 2.9.5
3) What is the IP address of your Host OS as seen from the inside the VM? That's where Xdebug should connect (as it's Xdebug that connects to IDE and NOT other way around).
When you first log in to the SSH there will be an IP address shown. This is what the IP should be for Xdebug. In my example, this was 10.0.2.2
4) xdebug.remote_connect_back: On -- try set it off and ensure that you have correct xdebug.remote_host (as Xdebug v2 may not fallback to remote_host value when autodetected IP fails.
This fixed my connection!
sudo nano /etc/php/7.4/fpm/conf.d/20-xdebug.ini
Then change:
xdebug.remote_connect_back=1
To:
xdebug.remote_connect_back=0
Save, and then restart the server.
Test the connection again. After this step I had a connection between the host and remote server but I also had to turn on path mapping in PhpStorm to get the debugger working 100%.
5) Ensure that PhpStorm is the one that listens on Xdebug port when "phone handle" icon is enabled (use netstat or alike to confirm) and is allowed in firewall.
6) If you know the correct IP and sure that PhpStorm is listening -- you can just use telnet from inside the VM and try to connect to IDE on Xdebug port -- if connected then IP, port and firewall is most likely set up correctly.
Even with the error messages, the telnet check was working. So it pointed to the issue being with the Xdebug setup rather than the handshaking between the host and remote server.
Thanks to LazyOne's comments for finding the answer and for presenting a great workflow to help identify the problem.

I was experiencing something very similar to what you described.
I was able to start a debug session from the xdebug cli tool (dbgpClient) which proved to me that it was an issue with phpStorm.
My project is using a legacy version of xdebug. (2.2.7)
Downgrading to phpStorm 2020.2.4 resolved my issue.
(It's one-click in the jetbrains toolbox to downgrade)

Thanks for the answers in this issue. It took me half a day to find out that xdebug 2.2.7 with php5.3.10 doesn't work on Phpstorm 2020.3. So I downgraded to 2020.2.4 and it works again.

Related

PhpStorm code coverage with remote Xdebug - can't connect (Xdebug 2.5.5)

I have a problem which I've been facing for 2 days. I've already configured my PHPUnit in PhpStorm, made code coverage save to log folders. I want to connect with Xdebug so I can make code coverage visible in my IDE. The problem is, I can't connect to remote Xdebug. I'm having a message: "Connection with 'Xdebug 2.5.5' was not established."
Guy from other team helped me to configure Xdebug as they have it configured for other project. I cloned this project, set it up and working, configured everything as he has it configured. And still cannot connect.
Port: 9000 (also got proxy for 9001-9005).
Windows firewall is off, ports are unlocked
IDE key is set on.
Tried with -dxdebug.remote_host command - still nothing
Set up our proxy host IP for Xdebug - still nothing.
Anyone has other idea?

PhpStorm debug with Laravel Homestead not working

I'm trying to setup PhpStorm to debug correctly within a Vagrant Homestead environment. Xdebug is correctly installed and I'm running PHP 7.1
After setting a breakpoint in my app the script passes through any breakpoints and I get this message:
debug session was finished without being paused
It may be caused by path mappings misconfiguration or not synchronized local and remote projects.
To figure out the problem check path mappings configuration for 'wedleague.loc' server at PHP|Servers or enable Break at first line in PHP scripts option (from Run menu).
I've checked the mappings and have this set up for the root of the project:
local path remote path
file://C:/vagrant/projects/wedleague /home/vagrant/code/wedleague
If I set to debug at first breakpoint I can work through the debug session.
Tried loads of answers here but nothing seems to work.
What can I try to get the debug session to work correctly?
Update:
I've also tried this mapping (as suggested)
file://C:/vagrant/projects/wedleague/public /home/vagrant/code/wedleague/public
Still not working with this configuration either :(
Step 1
Install PHPStorm 2017.X
Install Xdebug helper for chrome
Step 2
Via ssh (choose a tool like putty, WinSCP, MobaXterm etc.)
Install xdebug, in your case laravel gets Ubuntu 16.04 by default with Nginx so we need to follow these instructions
The values I used are
; Enable xdebug extension module
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.remote_host=10.0.2.2
in /etc/php.d/xdebug.ini
But note that I use my own vagrant installation (homestead is based on Vagrant) with CentOS and apache instead. Restart your virtual machine after config changes.
vagrant / homestead halt
and start again
vagrant / homestead up
Step 3
Config Xdebug helper extension in chrome by right clicking the symbol > options and set your IDE key to PHPStorm in the dropdown menu.
Configure PHPStorm, like a lot
hint: Settings has the shortcut ctrl + alt + s
Check the following settings. Don't forget to add both http and https in the Servers Setting and most important, don't read over the path mappings part.
And last but not least click these buttons, the first button with the phone horn actually has reversed icons in my opinion: when debugging it should have the little green part, altough logically red would mean stop, now it means start.
button 2 starts your url with a session var in the query string!
P.s. from your question: I think you need to go 1 level up root of laravel instead of public folders
edit: I just installed homestead at home and it comes with xdebug installed:

Vagrant not working with localhost extension on Chrome

I have a 2015 mac with macOs Sierra.
After too many problems with apache and php, I've decided to run Vagrant.
I'm running box.scotch.io for my work
Before Vagrant I configured the hosts file as follows:
127.0.0.1 devsite.localhost
127.0.0.1 sub.devsite.localhost
Remember I can't change the domains and extensions because it's not my project and I have to use those in order for some redirects and API's to work.
After Vagrant I changed it to:
192.168.33.10 devsite.localhost
192.168.33.10 sub.devsite.localhost
After editing the conf files inside vagrant, it worked fine. BUT not on chrome. I've tested in safari and firefox and it works fine.
For some reason, on Chrome those two were still showing me apache2 files.
So I've went and deleted the conf files from my local apache (for some reason). The only thing that changed was that now it shows me 403 forbidden (so still apache). I've tried shutting down apache. Now it shows me "This site can't be reached"
I've pinged them and it showed the correct IP (vagrant IP).
I've flushed the DNS (from terminal and from chrome) - still doesn't work.
I tried restarting chrome - nope. I tried restarting the laptop - nope.
So I thought that chrome dooesn't reload the hosts file, so I changed it from .localhost to .localhost2 or .local . Now it shows me the 404 from vagrant.
The weird part -> Everything i put with .localhost as extension doesn't work on Chrome... a.b.c.localhost will not work.
If I start apache, a.b.c.localhost will show me 403 forbidden from apache, even though it's not in the hosts file.
Note that in firefox and safari it works fine. But I really need chrome and the .localhost extension
I've already lost almost 2 days on this issue and I can't afford to lose another one
Find related information here: https://bugs.chromium.org/p/chromium/issues/detail?id=489973
In short: this seem to be a known Chrome feature: /etc/hosts is ignored for resolution of host names ending with .localhost, as OS X specific security mitigation. Comment 22 indicates a workaround: add 127.0.0.1 localhost. into /etc/hosts (and note the trailing dot after "localhost.").
For host management you can use a special plugin https://github.com/devopsgroup-io/vagrant-hostmanager AFAIR they resolved Chrome + MacOS issue

xdebug remote server and SFTP - cannot connect

I am trying to debug PHP files which sit on a remote server (on the same network) without success.
Here is my php.ini config for xdebug on the remote server where PHP and xdebug are installed:
xdebug.remote_enable=1
xdebug.remote_host=192.168.128.56
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=0
192.168.128.56 is the IP address of my PC on which my editor is installed.
I have tried to get this working with both Atom and Sublime Text 3 without success. I think that my path bindings may be incorrect.
I log into the remote linux machine using SFTP. I can then double click on php files in my application and they will open in my editor where I can work on them and save them. How can I set up the path bindings to debug these remote php files? I'm not sure what the second (local) part of the path binding should actually be? Do I need to add the location where the FTP software stores a temporary copy of the file I am working on as the local part of the binding?
I have tried the following:
URL - the address of where the app runs on the remote server:
e.g. http://www.mywebsite.com/testapp/
Path Binding - remote path to the application root on linux : path to the local copy of the files on my machine where the FTP software stores them:
e.g. /web/testApp/ : C:\Users\me\AppData\Local\Temp\scp18929\
I'm a little confused about how the path binding works, and what the values should be. Am I doing this correctly? Can this even be done?
If anyone can help that would be great.
Probably, the first thing to check is whether Xdebug actually tries to connect to your IDE. You can do that, by adding:
xdebug.remote_log=/tmp/xdebug.log
to your php.ini file. When you then initiate debugging, there should be information in the /tmp/xdebug.log file, where it will tell you where it tried to connect too, and whether the connection succeeded or failed.
If you get something like:
I: Remote address found, connecting to 192.168.128.56:9000.
E: Could not connect to client. :-(
That means that either your IDE wasn't listening for something, or that there is a firewall preventing an incoming connection, or that the IP address is incorrect.

XAMPP - Apache could not start - Attempting to start Apache service

While trying to start Apache using XAMPP, I was receiving - "Attempting to start Apache service..." message in XAMPP UI. No further details were available.
Where can I see the logs (I was running XAMPP as Admin) ?
IF PORT 80 IS NOT THE ISSUE!
Check to see if the port 80 is in use first as this can be an issue.
You can do this by typing "netstat -an" into cmd. The look for 0.0.0.0:80 under Local Address, if you find this is in use then follow the solution from #Karthik. However, I had a similar issue but my port 80 was not in use.
My XAMPP had wrong paths locations, steps to fix this:
1.Find out the Apache version you are using, you can find this by looking in Services (Control panel, Admin Tools, Services) and finding Apache in my case it was listed as Apache2.4
2.Close XAMPP.
3.Run cmd as admin.
4.execute 'sc delete "Apache2.4"' (put your version in place of mine and without the surrounding ' ', but with the " " around Apache).
5.execute 'sc delete "mySQL"', again remove the '' when you type it.
6.reopen XAMPP and try starting Apache
If you are having trouble with FileZill, Mercury, or Tomcat you could try it here too, but I have not tested that myself.
Hope this helps!
I realized it was a port issue since I was running IIS and other web servers in my machine. But I was more interested to see a detailed error message with the port number in the UI.
Seems like it was not logged in the UI or log file (at least in my case), but in the Event viewer (Control panel -> View Event Logs). Under the Even viewer -> Windows Logs -> Application
I could see a permission error something like the below one:
An attempt was made to access a socket in a way forbidden by its access permissions. : AH00072: make_sock: could not bind to address 0.0.0.0:443
To fix this permission issue for SSL port, Please change the below line in httpd-ssl.conf (C:\xampp\apache\conf\extra)
# When we also provide SSL we have to listen to the
standard HTTP port (see above) and to the HTTPS port
Listen xxx
Replace XXX with any valid port number that is open in your machine
If you are having issues with Port 80, then change the httpd.conf file (C:\xampp\apache\conf)
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 127.0.0.1:8000
I have also summarized other solutions that I came across:
Most often Skype blocks the Apache port. So terminate it and try again.
Find the process id (PID) that is using the Blocked port ( netstat -ano) and kill the corresponding process in Windows Task Manager.
For those who have accidentally (or not) changed one of the .conf files and apache does not run even after trying all the above solutions.
One easy way to track where the issue is located, is to run Apache via command prompt:
(On windows) : open command prompt as admin then navigate inside the bin folder of Apache , next run
httpd in order to run apache
C:\xampp\apache\bin\httpd
For my case it was :
someone had added a virtual host in the specific file that caused the problem . I commented the lines and Apache ran fine.
start xampp (as administrator),
(1) right click C:\xampp\xampp-control.exe, and run as administrator.
(2) unistall service module and then install service module.
(3) now try start the apache and mysql.
Check your DocumentRoot path (in httpd.conf); a typo there can cause this problem.
Had the same issue while updating to PHP7.2
Problem:
First I closed skype and then checked whether port 80 is not an issue. How you can check that? See #AlexT comment above.
In my case, port 80 wasn't an issue. So now I had to figure out what was wrong. So I checked Error Logs Control Panel > Even viewer > Windows Logs > Application and found following error against Apache2.4
httpd.exe: Syntax error on line 520 of C:/xampp/apache/conf/httpd.conf: Syntax error on line 18 of C:/xampp/apache/conf/extra/httpd-xampp.conf: Cannot load C:/xampp/php/php7ts.dll into server: The Apache service named is not a valid Win32 application.
Which means I had installed wrong PHP version. Actually I downloaded win64 version while the required version was Win32 for me.
So I downloaded correct version from: Download PHP 7.2.0 extracted it in C:/xampp/php folder, restarted the apache and it worked :)
I had the same issue, executing "setup_xampp.bat" in xampp folder solved my issue.
I had the same problem but it was because I had a previous version of xampp already installed and I tried to install a newer version. I had installed the newer version in another file directory (I had named the file directory xampp2). I solved the problem by uninstalling the newer version, renaming the old one (I renamed it xamppold) and I installed xampp again.
I guess if you haven't installed xampp in another file directory , it should be enough to reinstall xampp. If you are worried about your files , you always can make a backup before reinstalling xampp.
I solved the problem after watching the xampp activity log (the list of the bottom) and realizing xampp was trying to open the custom file path but I had another route path. If the first option didn't work, at least you can scroll up in the activity log and see what's error you get while starting as admin and trying to re install the Apache module or trying to start the module.
You may wander why I didn't just simply uninstall the whole thing from the beginning , and the answer would be because I had to tweak a couple of things in xampp for some different projects (from changing the ports , to add .dll to run mongo.db in Apache), and I was just too lazy to re-do everything again :b
I hope my answer can be helpful for anyone since this is my first time writing in stackoverflow :)
Cheers
In my case, with the same problem and Xampp window, I had copied \apache\conf\extra\httpd-vhosts.conf entries from an old Xampp version to a newly installed one so I could continue to open local projects in browsers. One of the vhosts paths was wrong. After deleting that entry Apache started without problem.
The reference by #Karthik to "in the Event viewer (Control panel -> View Event Logs" saved me time. It's all too easy to presume Xampp logs will point to the problem. It doesn't.
Also check if your xampp is installed in the main directory like C or D or E and not in or within a folder of that directory? i.e. ( "D:/Xampp" or is it "D:/something/Xampp") if its not in the main path of the directory, it will show this error.
copy your xampp directory from "D:\Something\Xampp" to "D:"
So it becomes like this "D:\Xampp"
and the issue will be resolved.
Starting Xampp as a console application (simply by doubleclicking xampp_start.exe in the Xampp root folder) was the only thing that worked for me on Windows 10 (no Skype, no Word Wide Web Publishing Service). WampServer and UwAmp also didn't work.
I had a hard-coded IP in httpd.conf and my local IP had changed which was causing my issue, changed IP over and all worked again
My scenario was different after I tested all the possible options. If you have changed the ports and still get the same problem, well here's something you can try out. This was done in Windows 7.
Step 1: Confirm the cause of the error by going to Control Panel -> System and Security -> Administrative Tools -> Event Viewer -> Windows Logs -> Application -> Error. Mine said "The Apache service named reported the following error:
httpd.exe: Syntax error on line 424 of C:/xampp/apache/conf/httpd.conf: Cannot load c:\xampp\php\php5apache.dll into server: The specified module could not be found." So I needed to change \php5apache.dll to the version of my php and apache version installed which was php7apache2_4.dll
Step 2: To get the correct name for your .dll php and apache file, got to C:\xampp\php. You will see something like php7apache2_4.dll with other files in the folder.
Step 3: Go to C:/xampp/apache/conf/httpd.conf and edit the configuration file and change "c:\xampp\php\php5apache.dll" to "c:\xampp\php\php7apache2_4.dll" in my case. Make sure you open the file as administrator save changes made.
Step 4: Run the xampp server and everything should work fine. Do not forget to shut down the xampp server before doing the changes to the apache configuration file.
Hope this helps. Cheers! :)
Try to install x86 version of XAMPP. The default XAMPP version on their website is x64 (maybe because I'm using x64 Windows 7).
download link here
I had this issue when I installed under Program Files, which they do not recommend due to write issues. This might only be a problem if you are not logged in as an admin and use a password to install. I just uninstalled and installed in a directory that did not need admin privileges.
Make sure Apache didn't get Disabled in Services (Control panel, Admin Tools, Services). If it's Disabled then Set it to Manual and it should run. That was my case, I found Apache Disabled.
Solution for my particular scenario (It had been working a couple days before getting borked):
Port 80 was not the problem, but something I had done while messing around with Services and Startup.
Type msconfig on Windows' Start menu
Click System Configuration
Screenshot for System Configuration
In the Services tab, search for Apache24 (Click "Hide all Microsoft services" in the checkbox at the bottom of the window to make it easier to find)
If its checkbox isn't checked, check it
If it was already checked, then this guide isn't going to help. However if it is:
Click OK, your PC will have to restart
Try once again! In my case Apache was already running once I opened Xampp
I had the same issue.Just click on services button.Then find apache and right cick > properties > set startup type as Automatic/ Manual. Now close apache and try again.It will work!
For me it wasn't a port or service issue; I had to re-run the XAMPP setup script. Although this didn't directly fix the issue for me, the script was much more verbose than the XAMPP log, pointing me in the right direction to actually solve the problem.
From the XAMPP GUI, click on Shell, type set, press Tab to autocomplete to the setup_xampp.bat file, and then press Enter to run it.
In my case I got the following output:
[ERROR]: Test php.exe failed !!!
[ERROR]: Perhaps the Microsoft C++ 2008 runtime package is not installed.
[ERROR]: Please try to install the MS VC++ 2008 Redistributable Package from the Mircrosoft page first
[ERROR]: http://www.microsoft.com/en-us/download/details.aspx?id=5582
This particular error is misleading. Although it specifies the Visual C++ 2008 Redistributable Package, PHP 7.4.x requires the Visual C++ 2019 Redistributable Package.
After installing that and following the prompt to restart, sure enough I'm now able to start Apache as normal.
make sure no space in front of the port number if you ever edited it.
From Xampp control panel, click on config (next to Apache), then choose Apache(httpd.config), search for listen 80 and change the port to another port.
If nothing works with you, I would suggest you download MAMP and use it instead.
It does the same thing, if not better.
Comment this lines from httpd.conf:
# Virtual hosts
#Include etc/extra/httpd-vhosts.conf
In the case you're using them it may solve.
when i run xampp control panel normal:
I had been run
I can’t start apache
So, I will run it with administrator:
I can run apache

Resources