简体   繁体   中英

Debugging Codeigniter with XDebug using PHPStorm

After setting up XDebug I succeeded in debugging php files with PHPStorm that are directly accessible.

But recently I started working with CodeIgniter and I worked through this tutorial . Now I was wondering if it was possible to debug specific MVC files, controller.php for example. Because after setting a breakpoint and starting to debug the controller file with PHPStorm it of course stated 'No direct script access allowed' since I directly accessed the script.

And when accessing the file manually eg http://localhost:63342/01_codeigniter_tutorial/public_html/index.php/controller it just shows a 404 page instead of the usual output shown when not opening it with PHPStorm.

So I'm wondering is there a specific documentation to read through for debugging CodeIgniter or am I just handling it wrong?

Thanks to LazyOne, who enlightened me in the comments I was able to find my mistakes and the solution.

The very first reason why a 404 page was shown when browsing the site with PhpStorm, was that I was using PhpStorm's built in web server and not my Apache. And said server doesn't handle mod_rewrite rules (which simplifies URLs) so for sites using CodeIgniter it won't work. And since the scripts aren't directly accesible it's not possible by simply clicking run in PhpStorm. So we have to initiate the debug request from the outside/web browser.

Now 2 things have to be done:

  • PhpStorm (or your prefered IDE) has to know that a debugging process is about to happen
    • Using PhpStorm you have to toggle the “Start Listening for PHP Debug Connections” button.
    • See more in their documentation
  • When browsing your site as you normally would (in my case localhost/01_codeigniter_tutorial/public_html/index.php/controlle r) you have to set a XDebug cookie since xdebug will not automatically start a debugging session when you open a script.
    • The easiest way is to install a Browser add on since you only have to click a button (I used The easiest XDebug for FF)
    • Read this for more information

After everything has been set up, you only need to refresh your page and the IDE should receive your debugging request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM