How to configure PhpStorm to use xdebug on a Vagrant machine - php

I am trying to configure xdebug to work in PhpStorm with my Vagrant machine, but I cannot figure out how to properly configure everything.
Here is the Vagrantfile I am using:
https://github.com/fideloper/Vaprobash
This Vagrantfile installs and configures xdebug for my Vagrant machine, but I'm not sure how to hook that up with PhpStorm. Between my xdebug.ini config, my web server config, and the PHP web app debug config, I cannot figure out how to get everything working.
When I click run->debug in PhpStorm, I get the following:
I have tried hacking away at the configuration details but have had 0 luck. Can anyone point out what I'm doing wrong here?

xdebug runs "backwards" to most typical server software one would deal with on Vagrant. IE, for apache you would fire that up on the VM and forward a port from the host to the VM so you could hit the server. Well, xdebug wants to push data from the VM to the host machine. Which means you need to feed xdebug the host's IP address -- which is probably the one the VM configured on the host only network and not your typical IP address -- and also to make sure that xdebug server is running and can accept connections.
Yeah that leaves a bit to be desired . . . .

Related

Docker / Xdebug Over LAN Server Multiple Developers

I'm attempting to setup Xdebug on some containers we have at the office. We have a Ubuntu server running Docker with the firewall wide open over LAN.
Ideally each developer would like to use PhpStorm (which we work over a mounted samba drive), to debug code on various websites.
We use Apache and have the jwilder nginx proxy to server multiple sites in docker.
I've attempted to setup a DBGp proxy with no luck so far. php.ini looks like this:
xdebug.remote_enable=1
xdebug.remote_host=containername
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
Inside the container for the DBGp proxy I have it on the same network as Apache and bind the 9001 externally e.g. - "9012:9001"
Using the IDE It does appear to detect the DBGp proxy correctly in PhpStorm. I listen for connections and place the IDE key in the get variable to start Xdebug session. I've tried with the Zend Debugger extension as well. At this point no break points are hit and the script just continues.
Do I need to do anything in PhpStorm to tell PhpStorm that the file directory doesn't match the directory on the server? Am I missing something in the php.ini file.
In this scenario could I simply use remote connect back for multiple developers and get rid of DBGg? Would it pose a security risk if the port was blocked via UFW on the docker host to the external world (I presume at the very least everyone could trigger Xdebug as these development sites are exposed to the world per say)?
hard to tell what's wrong and how to solve it at this point. did you try to break at the first line of code (run->break at first line)? if this does not stop your debug connection is not established. also try xdebug.remote_connect_back instead of defining the remote host

Xdebug unable to connect to client, where do I start debugging the debugger?

I'm setting up xdebug for php within sublime text, and xdebug keeps on logging errors related to being unable to connect:
Log opened at 2016-08-18 21:06:01
I: Connecting to configured address/port: localhost:9988.
E: Could not connect to client. :-(
Log closed at 2016-08-18 21:06:01
I hoped that debugging directly by going to http://localhost:9988 in my browser might help, but it simply displays the google chrome error page: "localhost refused to connect". Perhaps the error exists on the other end, that data can't be pushed to the sublime text client, I don't know. Sublime text xdebug does show the message "Reloading /var/log/xdebug/xdebug.log" when I run tests/etc, so it seems to be aware of the php code being run, just doesn't get any further.
So, I never thought I would have to debug xdebug itself, but: How can I debug the xdebug to code editor connection? If this were nginx, I would start debugging the virtualhost, but since it's xdebug... ...I have no idea where to start debugging the lack of an app to connect to?
## Various Configuration Settings ##
I am on ubuntu linux 14.04.
Here is my xdebug.ini conf if pertinent:
[xdebug]
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host="localhost"
xdebug.remote_handler="dbgp"
xdebug.remote_port=9988
xdebug.remote_mode = req
xdebug.overload_var_dump=0
xdebug.idekey = sublime.xdebug
xdebug.remote_log="/var/log/xdebug/xdebug.log"
;https://github.com/martomo/SublimeTextXdebug
Xdebug installed:
apt-cache policy php-xdebug
php-xdebug:
Installed: 2.4.0-5+donate.sury.org~trusty+1
Candidate: 2.4.0-5+donate.sury.org~trusty+1
Version table:
*** 2.4.0-5+donate.sury.org~trusty+1 0
500 http://ppa.launchpad.net/ondrej/php/ubuntu/ trusty/main amd64 Packages
100 /var/lib/dpkg/status
Module active:
php -m | grep -i xdebug
xdebug
Xdebug
phpinfo xdebug settings:
PHP debugging requires two components that collaborate: a PHP extension that acts as server and a software that knows how to talk to this extension and drive its functionality (it is the client).
However, despite the usual client-server protocols where the client connects to the server, the PHP debugger works the other way around: the server is the one that connects to the client (that should be started and listening on port 9000).
xdebug is the most known PHP extension for debug. There are many programs and program extensions/plugins that acts as clients for it. I didn't work with Xdebug package for Sublime (I didn't work with Sublime, in the first place) but the principles are the same.
How a debugging session works?
The client software (Sublime with the Xdebug package in your case) starts listening on port 9000 of localhost, waiting for the server to start the connection. It probably doesn't listen on the port all the time but only when the developer tells it so.
You start the PHP script to debug. xdebug doesn't kick in on all requests to the server but only when it finds a marker in the request. Depending on the SAPI used to run the script, the marker is either an environment variable (for CLI scripts) or a cookie or a GET or POST argument (for web pages). Read more on the "Starting The Debugger" section of the documentation.
When the PHP interpreter starts the execution of the PHP script, if xdebug finds the marker explained above then it tries to connect the xdebug client. Otherwise, it stays out of the way and lets the script run at its full speed.
When the debugging marker is present in the environment, the xdebug extension (the server) tries to connect to the xdebug client (by default on port 9000 of localhost but these settings can be changed as needed). If it cannot connect (because the client is not listening) then it logs the failure then puts itself out of the way and lets the script run at its full speed.
After it successfully connects to the client, the xdebug PHP extension either stops before running the first statement of the PHP script or runs the script until its execution reaches a breakpoint. This behaviour and the list of breakpoints are sent by the client to the server during their initial communication as the connection was established. Then the extension waits for commands from the client. The client displays to the developer the current state of the running script (the next statement to run, the values of the variables in the current scope etc) and waits for commands (run next statement, continue, add/remove breakpoints, watch some variable etc).
Why it doesn't work for you?
It's not very clear for me from your question but I'll assume you run the webserver (with the PHP interpreter and the xdebug extension) on the same computer you run the xdebug client (localhost). If this is not the case, don't despair. The solution is a command line away (read at the end of the answer).
From the information you posted in the question is clear that xdebug is installed, enabled and it works properly. The output of telnet localhost 9988 says nobody is listening on port 9988. The xdebug client should listen there.
I never worked with Sublime Text (and its packages). This article explains how to install and make it work. However, it doesn't explain how to configure it to listen on port 9988.
I would start by setting the PHP xdebug extension to connect to the default port (9000):
xdebug.remote_port=9000
and then, if everything works, I would try to find out how to configure the Sublime Text xdebug package to listen on a different port. Do you really need it to listen on a different port?
What if the web server and the xdebug client are on different computers?
If you need to debug a PHP script that runs on a remote machine the xdebug client listens on the local machine (on port 9000) and the xdebug extension tries to connect to port 9000 on the remote machine. A solution that is possible in intranets and VPNs is to configure xdebug to connect to port 9000 of the local machine but, apart from these conditions, it usually also requires changes in the firewall and/or other security software.
The easiest way to debug the PHP scripts in this situation if you have ssh access to the remote machine is to create a ssh tunnel from port 9000 of the remote machine to port 9000 of the local machine.
Assuming you use ssh to connect to the remote machine (to put the files on it), all you have to do is to append -R 9000:localhost:9000 to the command line you use to connect and start a ssh session to the remote machine.
As long as this connection is open, any connection request on port 9000 (the first 9000 on the command line above) of the remote machine (-R) is forwarded through the tunnel to the port 9000 (the second 9000 from the command line) of the local machine (localhost). This way the remote xdebug PHP extension is able to contact the remote xdebug client (assuming it is listening).
If you are using xdebug-v3, please try:
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
This should solve your issue.
Ok, so after extensive testings of different settings, here are my suggestions for debugging the problem for people who come after me:
Do not rely on testing with only 1 xdebug client! It's trivial to install two editors/IDEs, so get an alternate editor running to make it possible to see whether there is a problem with xdebug, or with the specific client!
There can be 3 locations that carry configuration for the xdebug+xdebug client combination! The client(or editor plugin) configuration, the 20-xdebug-conf.ini file (or in php.ini equivalent), and your project-specific configuration. Make sure all 3 locations are in sync in terms of port, path_mapping, etc.

Trick checkdnsrr in the dev environment

We use Vagrant to spin-up dev environemnt VMs. Within our VM infrastructure we have /etc/hosts setup to emulate our production urls. For example, if an app lives in production at https://foo.bar.com, then in our VM environment it is https://test-foo.bar.com. This has been working well but I recently hit a hiccup.
We use Symfony2, and have a field with a Url constrant and checkDNS set to true. That fires of a validator that runs the following.
if (!checkdnsrr($host, 'ANY')) {
Since this is actually reaching out to the DNS server for answers, and it of course knows nothing of my /etc/hosts file, and https://test-foo.bar doesn't really exist, this fails.
Is there an easy way to configure the VM so that this works, short of setting up a DNS server and pointing all the VMs to use it?
The VMs are running Ubuntu GNU/Linux.

setting up remotely accessible wamp server along with iis

I am new to Windows IIS and I need to run a php/mysql application on it. For local php development on windows, I have found WAMP to be the easiest.
But can WAMP be used in this case instead of installing php and mysql separately ?
This needs to be done on an ec2 Windows 2003 instance. So far, I have already tried installing WAMP and setting up apache to listen on port 8080 instead of 80. From inside the remote desktop, both IIS and WAMP work properly in parallel on their respective ports.
However, when I try to connect from another computer using the ip address http://184.**.***.***, IIS works fine serving the default web page but cannot connect to apache on http://184.**.***.***:8080.
Is it possible to use WAMP at all for this purpose and if yes, would there be any disadvantages in using it instead of installing php/mysql seperately ?
Edit :
I dont know if this is a problem of blocked 8080 port. To verify this I stopped IIS and configured apache to listen to 80. Even then http://184.**.***.*** doent show the WAMP homepage. IS anything needed to be configured in IIS ?
RESOLVED :
Added the port 80 in Windows Firewall Exceptions and it started working.
Also, its necessary to select "Put Online" in the WAMP tray otherwise it gives a forbidden response as suggested by some answers.
Thanks
I haven't used EC2 in this way before, but broadly speaking, I'd encourage you to use the same server for development and production environments if at all possible - the installation effort can be a bit of a pain, but it's nothing compared to developing an app locally and then finding an IIS configuration issue causes it to break on production.
This approach also lets you keep your PHP configurations in source code control - php.ini and any modules you're using - and automatically deploy them alongside your application; again, forgetting to deploy the correct PHP.ini usually makes your application do crazy things...
So, your choices appear to be:
- switch off IIS and have WAMP listen to port 80. Not sure WAMP is designed for production level traffic, but in the past, I've run low-traffic public websites in this way.
- work out why port 8080 is blocked, and if it can be unblocked. This would still require you to run your website on an unusual port, which makes for ugly and hard-to-communicate URLs.
- install PHP on your IIS instance. One benefit of having installed WAMP is that MySQL should already be up and running, and the basic PHP installation should also be there; getting PHP to run on IIS is no longer a dark art ([http://php.iis.net][1])
For my money, I'd go for the latter option...IIS is a production quality server, and it's clearly what Amazon want you to use in this instance.
Of course, running IIS on your development environment may be a problem.
Have you put the server online? Think it is offline by default, meaning it's only accessible from your local machine. It's an option in the systray menu to put it online.
If I remember well, there is an option "go public" (or "put online") on the system traya icon of wamp.
This option modifies the httpd.conf to authorize public access.
You should give a try.
On a side note, you can make php work with IIS. This is another option to help you manage your server. (Mysql and Php have to be installed separatly but, this is very easy to do as far as I remember :) )

Multiple users XDebug and PHP Debugging

How do you setup a multi-developer XDebug PHP environment?
I have the following setup:
I have a linux machine with Apache and Xdebug loaded and a php.ini file that I think is correct.
I found a python proxy script that I'm using to proxy the calls from the PDT Eclipse IDE's my developers are using to the Apache/Xdebug running on the same web server.
I set the idekey in php.ini to "ECLIPSE_DBGP" and for Xdebug to autostart
From the log information from the proxy it says that there is no server with the key "ECLIPSE_DBGP" and it stops the request.
Has anybody run into this or has a step by step setup to get this to work?
I have exhausted what I have found using google.
You can use ssh to tunnel the debug-connection back to your client machine. Eg. from your client machine, connect to the server with something like:
ssh -R 9000:localhost:9000 you#example.com
Then fire up your (local) debugger, and start the remote script. Xdebug (at the server) will now establish a connection to its localhost:9000, but since this port is forwarded back to your local machine, your (local) debugger will receive the connection.
If you use Windows on your client side, you can do the same thing with PuTTY.
See the documentation for Spectator for some more details.

Categories