Debugging Codeigniter with XDebug using PHPStorm - php

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?

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.

Related

How can I get xdebug to use the right page in vim while debugging a CodeIgniter app?

I have an Codeigniter app that I am trying to debug with vim. I have xdebug installed on my server and I am using the xdebug helper extension for chrome. The issue occurs when I initiate a debug session in vim with f5 and load the page I want to debug in chrome. Vim always outputs the index.php page of my app instead of the page I loaded in chrome. I don't understand what is happening. Any help would be appreciated.
All requests to a Codeigniter site start with a call to Index.php. This file is responsible for bootstrapping the framework and ultimately routing the request to the correct controller.
My guess is that there is a setting somewhere that has xdebug stopping on the first line of executed code - line 1 of Index.php. I'm not familiar with VIM so cannot tell you where to find or how to change this setting.
You will need to set a breakpoint somewhere in the file you want to debug. In other words, in the controller that the URL is going to run.

Change server mapping with phpunit and xdebug

I followed this tutorial to set up PhpStorm to use xdebug on vagrant: https://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm
When I got to step 7, and I got to this dialog, I chose my index.php file via manual selection, rather than using the radio dialog to import the mappings from my deployment server.
However, with that setting, I seem to only be able to set xdebug breakpoints in index.php, and not in any of the files / classes that index.php kicks off to do work.
I'd like to get that dialog (linked above) back, but it's not accessible through menus and invalidating the caches didn't help. Is there some way to get it to pop back up? Alternatively, is there some other way to set breakpoints in files called on by the index.php I already have mapped?

Issues debugging SWFUpload and PHP

I'm trying to add a SWFUpload instance to my website where multiple files will be uploaded in a queue. Currently, I'm working in a local LAMP environment running Netbeans and XDebug for my server side work.
I've followed the directions at the site and used this blog post to fill in the blanks.
My issue is that the test uploads execute according to the debug output of SWFUpload, but nothing shows in the upload path. In debug mode, none of the breakpoints in my server side script get touched.
I've triple-checked the file paths.
File permissions are all set to 755
This also occurs when I copied two of the demos to my server instance. In both circumstances, the upload_url php file breakpoints never got touched.
How can I debug this?
EDIT
I'm switching to a HTML5 method instead. however, it would be nice to identify some possible solutions to this issue for others who may run into the same problem.

Debugging CakePHP in Netbeans always stops on index.php

I've setup a CakePHP project in Netbeans and use xdebug for debugging. When I start a debugging session, Netbeans stops in the root index.php file on every request. I have to press continue and then my breakpoints are hit.
Is there a way to configure xdebug to avoid this behavior? It's pretty tedious having to hit continue on every request.
Thanks!
Answer in another post: here. Issue was not specific to CakePHP, but rather PHP debugging in general with Netbeans.
Try setting web root folder to APP/webroot. Right click your project and choose properties, then set your source folder to webroot.
Ref: cakePHP debug Netbeans
Hope it helps
Sudhir's answer pointed me into the right direction.
The following worked for me:
Go to project properties.
Click on Run Configuration.
Click browse button next to [Index File] field.
Select app/webroot/index.php.
Breakpoints finally working now!!!
I am sooo happy XD
( PS. I just made the move from Windows to OS X. Whatever installation you are running, make sure you are editing the correct php.ini file. Even PHP veterans like myself sometimes still end up editing the wrong stupid file. )
Paul is correct. This is a netbeans issue, not CakePHP. Uncheck "Stop at First Line".
The larger issue that many people face is getting debugging working in general. If you set the index field as user787301 suggested, then the debugger will launch to webroot/index and throw an error. The solution is to only set Web Root in project properties -> sources as Sudhir suggested.

Breakpoint not firing using PHP/XAMPP/NetBeans/Moodle

Bit of an obscure one this. My setup is all running on my local Windows machine; I've got NetBeans IDE installed, a local XAMPP server with XDebug running, and an installation of Moodle with some custom addons in the mod directory.
I can happily create breakpoints in PHP pages (including the main Moodle ones), but any breakpoints I place on php files in the mod directory never fire (on my mods, or any of the inbuilt ones). I thought Moodle might be doing some "magic" to display files in the mod directory, but my browser shows the url as http://localhost/moodle/mod/view.php - and that's the file I've set my breakpoint in.
Has anyone got any experience with debugging Moodle addins, or could possible point me in the direction of how to troubleshoot the breakpoint not firing? I've tried the Moodle site, but can't find anything relevent.
Actually, I think I've figured it out. If I tell it to debug that particular file it will 404 (it doesn't put the directories in, guess it's a bug), but if I then manually go to http://localhost/moodle/mod/view.php?XDEBUG_SESSION_START=netbeans-xdebug (which errors, no parameters are being passed in), and THEN manually navigate to Moodle then my mod breakpoints fire correctly.
All very bizarre, but it seems to be a usable workaround. I'm guessing the mods are running under some kind of different PHP session.
I'll keep this answer here in case anyone else has this bizarre problem.

Categories