debuggingnginxphpstormxdebugx-accel-redirect

Can PhpStorm debug a file that has been redirected to using Nginx's X-Accel-Redirect?


I'm using Nginx's X-Accel-Redirect to serve a file (redirected.php) that is outside of the webroot. The webroot is /usr/share/nginx/html and the file I am wanting to debug is being served from /usr/share/nginx/downloads

I begin Xdebug in the browser (debugging works at this stage). At some point the browser makes a request for website1.com/learning/downloads/url, Nginx redirects the request to redirected.php using the below rule

# Enable X-Accel-Redirect
location /learning/downloads/ {
root /usr/share/nginx/downloads;
rewrite ^/(.*)$ /redirected.php last;
}

Unfortunately, I can't get redirected.php to pause on any breakpoints.

Is it not possible to debug when using X-Accel-Redirect with PhpStorm? or is it more likely to be a mapping issue? Suggestions on how to overcome this issue would be much appreciated.


Solution

  • It was a mapping issue. Part of the problem was due to redirected.php being in a folder outside the webroot.

    To fix it, I went to File -> Settings -> Languages & Frameworks -> PHP -> Servers and configured it as in the picture below.

    Phpstorm Config for debugging files outside webroot

    I also added xdebug_break(); to the code in redirected.php