mod_rewrite, xdebug, & remote debugging
Forgive me if this has been asked before I searched around and couldn't find anything related to it. I've been having a problem with xdebug and after several hours attempting to figure it out I have, however I cannot find the appropriate solution.
Here Goes:
I'm trying to debug an application located within a framework (Lithium, to be exact) and that uses mod_rewrite so that urls can be mapped to GET calls in a clean fashion (e.g. /pages/about is really mapped to index.php?url=pages/about). The problem is that while using these urls xdebug will connect to phpstorm but it will not process breakpoints or anything - it's an instant connect and disconnect. I'm assuming because it doesn't know the path to follow, but given the nature of these dynamic urls there's no way to map every possibility to the files.If I access mysite/controller/action/arg1/arg2 nothing occurs, if i change the url to mysite/?url=controller/action/arg1/arg2 it happily works. The problem is this is somewhat inconvenient plus debugging urls inbetween pages (say a url which it's sole purpose is to process a form and forward the user to a success/deny page) is not so feasible.
Is this a known issue, and what can I do to resolve it?
Thanks for you time, Howard
Please sign in to leave a comment.
sounds similar to a problem i was having the other day:
http://devnet.jetbrains.net/thread/293156?tstart=0
have you tried setting xdebug remote autostart to on:
xdebug.remote_autostart=1
in php.ini
Then click the red telephone button on PhpStorm to get the IDE to listen for incoming connections.
Put a breakpoint anywhere in anyfile and if the file is run, the breakpoint should be hit and stop.
Hope it works.
Yes I've tried with autostart on and off, the system is listening for connections - it does work if I'm not accessing a rewritten URL, but it won't work* if I access a mod_rewrite URL.
*in not working i mean breakpoints don't work, a connection is still made and immediately disconnected - but it never actually processes. I'm assuming it's trying to go by the URL path and not the actual accessed file path
I'm using rewritten URLs all the time (under Apache on my work PC and IIS (URL Rewrite module) on home PC/production servers) in similar fashion (custom framework where I have single entry point in index.php) and it does work fine.
Most likely it is mapping issue (or some other settings).
It may also be a bad break point (some breakpoints cannot be hit by xdebug -- like multiline array definitions or method/function declaration) -- in this case try another breakpoint.
Please provide more details.
P.S.
Xdebug and PhpStorm work with real file names, not URLs
The breakpoint is an essential piece which runs the framework - so it'd have to be hit - I'll provide details.
index.php sans comments - tried brakpoints on the require and echo - They work, as long as i'm not rewriting the url
I put these breakpoints in place to be sure the system was loading the file - but it doesn't seem to make the connection. As long as it loads this files, any breakpoints in any file that's loaded from there also work ok.
This is the rewrite for .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !favicon.ico$
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
I have mentioned about bad breakpoints just in case you have set it on such line. The code snippet you have provided has no such lines, so you can ignore this part.
The breakpoint on "require" line should work absolutely fine (as I understand it is part (or even whole content) of index.php).
Please describe how you do debugging:
1) do you have debug mappings setup (Settings | PHP | Servers) ?
2) do you use any debug configurations (which one, settings) ?
3) if no debug configurations are used, how do you activate debugger (bookmarklet, browser extension etc)? Do you activate debug listener (that icon with red phone handle) ?
1) I don't use mapping - everything's local so it's 1:1
2) Debug Settings
hosts is hacked to 127.0.0.1 for the address I test
running apache on port 86 (for this instance)
ide key (session is) is configured
port is configured
xdebug config
xdebug.idekey=...
xdebug.profiler_append = 0
xdebug.profiler_enable = true
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "C:\noinstall-bins\xampp\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.xdebug_profile.%p"
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler=dbgp
xdebug.remote_mode = "req"
xdebug.remote_port = 9000
xdebug.trace_output_dir = "C:\noinstall-bins\xampp\xampp\tmp"
3) I click the phone icon to begin listening and from the dropdown box select the configured remote debugger in the run/debug configurations window
It's a bit confusing to me .. so I will describe how I do have it setup here, and you compare to what you have (and may be try the same).




1) I assume you are using latest EAP build (PS-102.114) and xdebug (2.1.0).
2) Settings | PHP | Servers. You need at least one entry -- even if you not going to use mappings (there is tick box for that) as everything is local. You need to specify host name, port and debugger. This is what I have (I do have mappings ticked, as I'm using symbolic links on some libraries)
3) Debug configuration. If you use debug configuration then you do not need to use debug listener (phone icon). Here what I'm using right now:
4) Now I just select this configuration and click Debug button
This will launch that page in website with some IDE Key. If you have breakpoints -- it will hit them. If you do not need to debug that page -- just finish debugging it somehow (by clicking "Resume program execution" button and then navigate to the page you actually need to debug (or just paste URL you need to debug on the same tab/browser window). Alternatively -- alter "Start URL" field to much the page you need.
Of course, you can use "PHP Remote Debug" configuration, but then you have to use some bookmarklet/browser extension etc to activate debug session (as you need to pass correct IDE key somehow). Here is an example of such configuration (pretty much the same as above):
I find this one more convenient to use compare to the previously mentioned (Web App) as you can turn on/off debugging any time (straight on the page you need to debug).
If you use debug listener (phone icon) before (or after) activating such debug configuration (which as I understand you already do), then PhpStorm should accept any IDE key (have not really tested this but should work like that).
I see you have set xdebug.remote_autostart = 1 -- this should tell xdebug to initiate debug connection even if ide key (xdebug cookie/parameter) is not present.
Now, taking all this info into cosideration, I think that the issue may be with #2 (that is my understanding here as I cannot obviously see what is going on specific moment of time on your PC there) or with IDE key being missing. Maybe (just maybe) it has something to do with port number (I think there was a ticket mentioning this part in some context, but it was marked as fixed:WI-4552).
If nothing of the above will help you -- I suggest check the logs (USERHOME/.WebIde10/system/log/idea.log). If the log is too big/too much stuff there -- close PhpStorm, find logs, delete them (or better back them up just in case), start PhpStorm and try to debug again -- you should have the most recent & appropriate logs. You should be able to see if and why PhpStorm does not activate debugging (if you cannot "read" them (find the reason), then post them here (attach to the post) & wait for Nikolay Matveev -- he deals with debugging and will tell you for sure).
Wow, I really appreciate the time you put into this - the php web application does work. I never used that icon just tried to use the phone and match ports/id's - This is working though and I can move forward now :)
The web application is good enough because it holds the key (i didn't know this) in a session and you cna keep navigating until you hit the pages needed.
Thanks again so much!
Best Regards,
Howard
Extra note: using that icon with the remote debugger the ide likes to yell at me saying it's already registered.. not sure what that's about.
There is another way (which may be even better/more convenient -- depends on your workflow and habits) -- to control xdebug from browser (via browser extension). Some of such browser plugins can even trigger xdebug profiler on/off (I see from your xdebug settings that you have it constantly on -- this hurts performance and pretty useless during debugging).
Here are my settings for xdebug profiler :
Xdebug browser extensions:
Firefox: easy Xdebug (can trigger profiler)
Chrome: Xdebug helper (can trigger profiler)
Opera: xdebug (debugger only, for now)
How to use it:
1) You already have mappings
2) turn debug listener on (phone icon)
3) no debug configuration is required (but you may want to comment out xdebug.remote_autostart = 1)
4) just trigger xdebug session in browser extension (it will set xdebug cookie) and navigate to the page you need to debug.
If now you need to see the page with no debugging involved then just deactivate xdebug session in browser extension (this will remove cookie) and refresh the page (or navigate to another url).
Andriy,
Great! I am very appreciate you for help!
Thank you!
Hello Howard,

Just want to understand why "Listen Debug connections" button is not working for your case.
Please enable "break at the first line(for external connections)" option in Project Settings -> PHP -> Debug and try to use button again.
Thank you for feedback!
is the phone meant to be clicked while a remote debug configuration is active and it says 'waiting for incoming connection with ide key ...'?
if no, nothing happens until i do - if yes - with break on the first line it appears to have a mapping error. This also points something out, it seems maps with errors are url escaped and spaces come back as %20 - could this throw phpstorm off some? (this current path has no spaces, i removed them just in case)
-- setting the root path resolves this - but remote only works with the phone icon active, is this intended behavior?
can we get an option to autobreak or at least report when a mapping failed, instead of just connect/disconnect?
Hello Howard,
Sorry for delay.
No. Use remote debug configuration if you need to specify "ide key' of debug session. Phone button will work with any debug connection.
No, remote debugging should work with Php Remote Debug configuration as well as with Php Web Application run configuration. Please describe you remote debug configuration settings.
Thanks for great ideas! We are going to implement this features in the nearest time.
Thanks for feedback!
Howard,
We implemented this behaviour. PhpStorm will break at the first line if it cannot find a path mapping for original file since the next EAP.
Thanks for feedback!
great to hear! The other issue (using a key when debugging remote) seemed to be related to the mapping, however it didn't seem that 'break on first line' worked there, only from the primary preferences.
Howard,
Please elaborate. 'break at the first line' option from 'PHP Remote Debug' run configuration works for me.