如何使用Nginx启用xdebug? [英] How to enable xdebug with nginx?
问题描述
我的情况如下:
我有一个带有PHP 5.4.9-4ubuntu2.2,nginx/1.2.6,php5-fpm和Xdebug v2.2.1的VM(Ubuntu服务器13.04).
I have a VM (Ubuntu server 13.04) with PHP 5.4.9-4ubuntu2.2, nginx/1.2.6, php5-fpm and Xdebug v2.2.1.
我正在使用PhpStorm 6.0.3(已在VM上部署)开发应用程序.
I'm developing an app using PhpStorm 6.0.3 (which I deploy on the VM).
我的问题是,每当我尝试启动调试会话时,IDE都不会从Web服务器获取连接请求(因此,该会话永远不会启动).
My problem is, whenever I try to start a debugging session, the IDE never gets a connection request from the webserver (And thus, the session never starts).
我浏览了很多有关xdebug配置的建议,发现没有什么有用的.
I looked through a lot of recommendations about xdebug configuration and found nothing useful.
我最近意识到,如果我自己通过浏览器设置XDEBUG_SESSION cookie(感谢FireCookie),则可以调试我的应用程序...所以我猜想是有某种阻止Web服务器将cookie发送回客户端的原因.
What I recently realized is that if I set the XDEBUG_SESSION cookie myself through the browser (Thanks FireCookie) I can debug my app... so my guess is there's something keeping the webserver from sending the cookie back to the client.
问题是,我在不同的项目中使用了相同的IDE配置,该配置已部署到不同的基于CentOS的VM(带有lighttpd)中,并且工作正常.
The thing is, I'm using the same IDE configuration in a different project, which is deployed into a different CentOS based VM (with lighttpd), and it works just fine.
我试图将当前项目部署到这样的VM中(将网络服务器更改为NginX),并且一切正常(不幸的是,我丢失了该VM并且无法检查config:().
I tried to deploying my current project into such VM (changing the webserver to NginX) and it worked allright (Unfortunately I lost that VM and can't check the config :().
所以...这是我的NginX配置:
So... here's my NginX config:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
location / {
try_files $uri $uri/ /dispatch.php;
}
#
location ~ \.php$ {
root /var/www/bresson/web;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index dispatch.php;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
include fastcgi_params;
#fastcgi_pass 127.0.0.1:9009;
}
}
fpm配置(/etc/php5/fpm/pool.d/www.conf):
fpm config (/etc/php5/fpm/pool.d/www.conf):
listen = /var/run/php5-fpm.sock
xdebug.ini:
xdebug.ini:
zend_extension=/usr/lib/php5/20100525/xdebug.so
xdebug.remote_port=9000
xdebug.remote_enable=On
xdebug.remote_connect_back=On
xdebug.remote_log=/var/log/xdebug.log
任何想法将不胜感激.谢谢!
Any idea will be much appreciated. Thanks!
我尝试的另一件事是从php启动会话,我发现会话cookie的创建没有任何问题...
Another thing I tried was to start a session from php and I saw that the session cookie was created without any problem...
第二次
我想我找到了问题所在:URI.
I think I found where the problem is: the URI.
我写了另一个脚本来尝试配置参数和内容(一个简单得多的脚本),它可以正常工作!.
I wrote another script in order to try configuration parameters and stuff (A much simpler one), and it worked right out!.
所以最终我发现问题是查询参数(即:XDEBUG_SESSION_START=14845
)没有到达我的脚本.
So eventually I figured the problem was that the query parameters (i.e.: XDEBUG_SESSION_START=14845
) were not reaching my script.
问题是我的起始URI,其格式为/images/P/P1/P1010044-242x300.jpg
.通过一些虚拟主机配置,我应该能够将其路由到类似/dispatch.php/images/P/P1/P1010044-242x300.jpg
之类的东西,并将其余的URI用作参数.所以...我还没有找到一个解决方案,但是现在我有了一个可行的解决方法(将我的起始URL指向/dispatch.php
),这将在一段时间内完成.谢谢
The problem is my starting URI, which is of the form /images/P/P1/P1010044-242x300.jpg
. Through some virtual host configuration I should be able to route it to something of the like /dispatch.php/images/P/P1/P1010044-242x300.jpg
, and use the rest of the URI as parameters. So... I haven't found a solution per se, but now I have a viable workaround (pointing my starting URL to /dispatch.php
) which will do it for a while. Thanks
推荐答案
以防万一有人在读这本书……我明白了!
Just in case there's someone reading this... I got it!
问题是nginx的配置.我刚刚从某个地方复制了一个模板,但是现在我读了一些,发现我的特定配置要简单得多:
The problem was nginx's configuration. I had just copied a template from somewhere, but now I read a little more and found out that my particular config was much simpler:
location / {
root /var/www/bresson/web/;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/dispatch.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
在我的情况下,每个请求都必须转发到我的前控制器(然后由后者分析URI),所以这真的很简单.
In my case, every request has to be forwarded to my front-controller (which then analyzes the URI), so it was really simple.
这篇关于如何使用Nginx启用xdebug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!