remote xdebug fpm works, but not with rewrite
I'm running PHPStorm and Apache 2.4/ php-fpm7.0 on an AWS server. PHPStorm output is redirected to a local X Server and the website in question is accessed through a domain name locally set.
In a Symfony project I can debug a test file that is directly accessible, but urls that are rewritten with Apache mod_rewrite do not trigger breakpoints.
My Xdebug configuration:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=127.0.0.1,172.25.20.xxx,13.xx.xx.xx
xdebug.remote_log=/home/jochen/projects/xdebug.log
When I debug http://public.domain/phpinfo.php the debugger stops at the breakpoint and the xdebug.log is written
When I debug http://public.domain/app_dev.php/some/route, the debugger does not stop at any breakpoint, neither in app_dev.php, nor in a subsequent file.
I understand this should be solved with a path mapping, however I have tried:
1) none
2) /home/jochen/projects/mgr/ -> /home/jochen/projects/mgr/ only
3) /home/jochen/projects/mgr/ -> /home/jochen/projects/mgr/ and
/home/jochen/projects/mgr/site/app_dev.php -> /home/jochen/projects/mgr/site/app_dev.php
4) /home/jochen/projects/mgr/ -> /home/jochen/projects/mgr/ and
/home/jochen/projects/mgr/site/app_dev.php -> /home/jochen/projects/mgr/site/app_dev.php/
(note the traling slash, however from other posts this doesn't make sense anyway)
How else can I get this going?
Please sign in to leave a comment.
Hi there,
Having URL Rewriting does not affect debugging at all ... as xdebug works with .php files and not URLs. I'm debugging nice URLs all the time (locally though; Laravel 5.4, WordPress, custom "frameworks")
It's possible that code where breakpoint is placed may simply not be executed at all (e.g. due to framework caching mechanism .. or actually non-executed line).
Path mappings is only needed when path on remote server does not match the one on local (e.g. "/var/www/site.com" vs "/Users/USERNAME/projects/site.com") .. or you have symbolic links somewhere in the path (xdebug works with final/resolved paths while IDE uses them as is).
Therefore there is no point to specify path mappings if they all the same.
1) What xdebug log has to say about it? Are the paths correct? Please share the log (unmodified file paths please; IPs can be partially xxx)
2) Does placing "xdebug_break();" in actual PHP code (programmatic breakpoint; will also initiate debug session) helps in any way?
3) php-fpm by default uses the same 9000 port as xdebug. I would suggest to change xdebug port to 9001 or something else (in both php.ini and IDE settings). But then ... it should behave the same in both real and nice URL cases...
4) How IDE behaves -- does it register incoming xdebug request but fails to map the files .. or what?
5) https://intellij-support.jetbrains.com/hc/en-us/articles/207241115-How-to-Collecting-PhpStorm-WebStorm-debug-Logs -- adding extra logging should allow to see what is happening on IDE side.
P.S. I did not get your setup -- is that a "local" environment (where IDE and web server are on the same computer/server, even if they accessed via some sort of Remote Desktop) or it's a remote debug (IDE is on local computer and web server is elsewhere (LAN/Internet/VM/etc)
Hi there,
Sorry I have left this so long.
To explain my setup: I have a Ubuntu 16 machine on Amazon AWS, from which I start PHPStorm. I redirect output to a local XServer/ SSH program called MobaXterm. So development is local, but the browser debug connection comes from external.
The app I am debugging is Symfony and I am debugging it successfully on another machine, however the browser connection is local and its mod_php.
The problematic server is php-fpm.
In regards to your questions:
1)
With /etc/php/7.0/fpm/conf.d/20-xdebug.ini:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
#xdebug.remote_host=127.0.0.1,172.25.20.120,13.210.31.xxx
xdebug.remote_log=/home/jochen/projects/xdebug.log
a) http://mydomain.com/phpinfo.php?XDEBUG_SESSION_START=1 stops at first line
b) http://mydomain.com/app_dev.php/site/1?XDEBUG_SESSION_START=1 does not stop
For a) my Xdebug log is
Log opened at 2017-11-03 01:29:40
I: Connecting to configured address/port: localhost:9000.
W: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///home/jochen/projects/mgr/site/web/phpinfo.php" language="PHP" xdebug:language_version="7.0.21-1~ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="20678" idekey="1"><engine version="2.5.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>
With /etc/php/7.0/fpm/conf.d/20-xdebug.ini:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=127.0.0.1,172.25.20.120,13.210.31.xxx
xdebug.remote_log=/home/jochen/projects/xdebug.log
a) http://mydomain.com/phpinfo.php?XDEBUG_SESSION_START=1 does not stop
b) http://mydomain.com/app_dev.php/site/1?XDEBUG_SESSION_START=1 does not stop
for a) my xdebug log is:
Log opened at 2017-11-03 01:38:17
I: Connecting to configured address/port: 127.0.0.1,172.25.20.120,13.210.31.xxx:9000.
W: Creating socket for '127.0.0.1,172.25.20.120,13.210.31.xxx:9000', getaddrinfo: No such file or directory.
E: Could not connect to client. :-(
Log closed at 2017-11-03 01:38:17
With /etc/php/7.0/fpm/conf.d/20-xdebug.ini:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=13.210.31.xxx
xdebug.remote_log=/home/jochen/projects/xdebug.log
a) http://mydomain.com/phpinfo.php?XDEBUG_SESSION_START=1 stops at first line
b) http://mydomain.com/app_dev.php/site/1?XDEBUG_SESSION_START=1 does not stop
for a) my xdebug log is
Log opened at 2017-11-03 01:39:15
I: Connecting to configured address/port: 13.210.31.xxx:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///home/jochen/projects/mgr/site/web/phpinfo.php" language="PHP" xdebug:language_version="7.0.21-1~ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="20831" idekey="1"><engine version="2.5.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>
13.210.31.xxx is the public IP address of my server on the Internet and resolves for its hostname. I would prefer to use this, so I don't have to reconfigure the server when my home computers IP address changes.
2) xdebug_break(); does not make any difference
3) I had fallen for this before I put up this question, but have reconfigured it, so php-fpm uses ports beyond 9000
4) This I can't answer I think. Because the IDE is shown over X/ssh session, it does not take focus when the debugger stops. I haven't figured out how to do this yet, if possible.
I get "Debug session was finished without being paused" when I add path mappings, but then I can only add path mappings that map the same path names, as they are identical. (debugger, Apache and PHP-fpm are on the same machine)
5) With additional logs I get
a) When debugging phpinfo.php
2017-11-03 14:51:44,289 [15095937] DEBUG - il.connection.ServerConnection - Incoming connection on port 9000 from 13.210.31.246
2017-11-03 14:51:44,291 [15095939] DEBUG - .connection.PhpDebugConnection - 927056607#----connection started
2017-11-03 14:51:44,294 [15095942] DEBUG - .connection.PhpDebugConnection - Xdebug protocol doesn't support command: 'feature_set extended_properties 1'
2017-11-03 14:51:44,302 [15095950] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@63f7ce0d
2017-11-03 14:51:44,302 [15095950] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@6cb712d6
2017-11-03 14:51:44,319 [15095967] DEBUG - p.debug.common.PhpDebugProcess - 2000614753# Stop at ('file:///home/jochen/projects/mgr/site/web/phpinfo.php':7)
2017-11-03 14:51:44,319 [15095967] DEBUG - p.debug.common.PhpDebugProcess - 2000614753# remote: 'file:///home/jochen/projects/mgr/site/web/phpinfo.php' <-> local: '/home/jochen/projects/mgr/site/web/phpinfo.php'
2017-11-03 14:51:44,319 [15095967] DEBUG - p.debug.common.PhpDebugProcess - 2000614753# remote: 'file:///home/jochen/projects/mgr/site/web/phpinfo.php' <-> extracted: '/home/jochen/projects/mgr/site/web/phpinfo.php'
When debugging /app_dev.php/site/1
- nothing
However (bingo) when debugging /site/1, debugging works.
In Symfony, app_dev.php/ prefix is used to switch into a different environment with debug toolbar.
I'm also wondering if my PH-fpm configuration may affect this, as I had problems previously with rewriting not working when the url contains .php (However rewriting does work, it just doesn't debug.
My PHP FPM conf:
<VirtualHost *:80>
ServerName mgr.d.xxx.xxx
ServerAdmin jd@automatem.co.nz
DocumentRoot /home/jochen/projects/mgr/site/web
CustomLog /var/log/apache2/mgr-access.log combined
ErrorLog /var/log/apache2/mgr-error.log
<LocationMatch "^(.*\.php)$">
ProxyPass fcgi://127.0.0.1:9204/home/jochen/projects/mgr/site/web
</LocationMatch>
</VirtualHost>
Also, Symfony .htacess is:
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks
# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve
# to the front controller "/app.php" but be rewritten to "/app.php/app".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Again, thanks for any help.
Jochen
Wow .. LOTS of info at once.
1. You show xdebug log for a) .. but never for b). Does xdebug even tries to connect somewhere in such b) case or nothing in the log at all?
I guess it's nothing... so xdebug simply not even trying to connect?..
2. >I : Connecting to configured address/port: 127.0.0.1,172.25.20.120,13.210.31.xxx:9000.
AFAIK xdebug.remote_host should contain a single IP address so you cannot list multiple addresses. https://xdebug.org/docs/all_settings#remote_host
3. >13.210.31.xxx is the public IP address of my server on the Internet and resolves for its hostname. I would prefer to use this, so I don't have to reconfigure the server when my home computers IP address changes.
In you first xdebug log it connects to localhost:9000 and it works for a) URL case. Plus, as I understand, the PhpStorm is possibly installed on the actual server (or perhaps has some SSH tunnel that forwards xdebug connection to it). Therefore I would assume that using 127.0.0.1 for xdebug.remote_host should be OK (so no need for real public IP).
4. >However (bingo) when debugging /site/1, debugging works.
So .. it's working? -- not with "/app_dev.php/sites/1" but with just "/sites/1" ?
TBH -- I do not remember dealing with such "/index.php/rest-of-url" URL in my debugging practice. I've only dealt with either exact real URL ("/some/file.php") or a "proper" nice URL ("/some/nice/page") where nice URL is either getting transformed to a real file using mod_rewrite rules (or URLRewrite module when running under IIS) or by framework itself (when all requests to a non-existing resource just points directly to a entry script (app.php in your case).
E.g. standard WordPress
Typical Laravel (relevant part of it)
Considering your rewriting rules (which is hard to read for me after not using Apache on "proper" level for quite some time) .. the actual issue that does all that might be somewhere there. At the same time -- it's Symfony project -- very popular framework... so you would not be alone in your situation.
I wonder if it will work with "/app.php/sites/1" kind of URL...
In any case: if xdebug is not trying to connect when debug session does not work (but works in other case with simpler/"proper" URL) ... then it's obviously an issue at web server config level and not really a PhpStorm (no incoming debug session no reaction from IDE -- as simple as that).
But if it tries to connect (which it should .. since you have xdebug.remote_autostart=1) ... then it's a different story.
What I may suggest (if you still need it .. and if you will find it useful):
1) If you server is not busy (dev only; you can stop it as needed etc) and you have time and desire -- configure Apache to do verbose mod_rewrite log (http://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging) maybe you can spot some nuance there -- maybe it gets served differently.
2) Try comparing phpinfo() output made via "/sites/1" and "/app_dev.php/sites/1" (make that or similar script returning phpinfo() output for test purpose) -- maybe you can spot some difference in xdebug/environment sections.
3) Look at StackOverflow / Symfony forums for the similar topics
I have similar issue. PhpStorm doesn't break on breakpoints when the url is rewritten in .htaccess. It still does break on xdebug_break(). It started happening only after I changed apache to use FastCGI (without PHP-FPM).
I have not had time to look at my previous setup, but I found that the PHP FPM configuration I reported here has issues with these kinds of urls in general: site.com/somefile.php/someurl/part/after
They are not picked up by PHP FPm at all and I imagine that would stop them being debuggable.
For this problem I found changing my Apache configuration to this helps
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://127.0.0.1:9110/
</FilesMatch>
@Stann435 Maybe you could check how your Apache config looks like and try this?