Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 e.g. 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?

like image 302
Elektropepi Avatar asked Jul 30 '15 11:07

Elektropepi


People also ask

How does PHP xdebug work?

When Xdebug is running, it will call back to your IDE (like PhpStorm or VS Code) from the server where it's running. Your IDE will sit and listen for that connection on a specific port (typically port 9000 or 9003).


1 Answers

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/controller) 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.

like image 160
Elektropepi Avatar answered Oct 31 '22 15:10

Elektropepi