title: How to enable xdebug with nginx?
body: <p>My situation is the following:</p>
  
  <p>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.</p>
  
  <p>I'm developing an app using PhpStorm 6.0.3 (which I deploy on the VM).</p>
  
  <p>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).</p>
  
  <p>I looked through a lot of recommendations about xdebug configuration and found nothing useful.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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 :().</p>
  
  <p>So... here's my NginX config:</p>
  
  <pre><code>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;
      }
  
  }
  </code></pre>
  
  <p>fpm config (/etc/php5/fpm/pool.d/www.conf):</p>
  
  <pre><code>listen = /var/run/php5-fpm.sock
  </code></pre>
  
  <p>xdebug.ini:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Any idea will be much appreciated. Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Another thing I tried was to start a session from php and I saw that the session cookie was created without any problem...</p>
  
  <p>2nd Edit:</p>
  
  <p>I think I found where the problem is: the URI.</p>
  
  <p>I wrote another script in order to try configuration parameters and stuff (A much simpler one), and it worked right out!.</p>
  
  <p>So eventually I figured the problem was that the query parameters (i.e.: <code>XDEBUG_SESSION_START=14845</code>) were not reaching my script.</p>
  
  <p>The problem is my starting URI, which is of the form <code>/images/P/P1/P1010044-242x300.jpg</code>. Through some virtual host configuration I should be able to route it to something of the like <code>/dispatch.php/images/P/P1/P1010044-242x300.jpg</code>, 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 <code>/dispatch.php</code>) which will do it for a while. Thanks</p>