How to properly setup debug configurations in PhpStorm - php

I have a project in PhpStorm and I would like to be able debug any php file in any folder. The only way I managed to debug a php page was to set it explicitly in the debug configuration:
Note that I'm typing the full path to a php file in a specific folder. Now if I want to debug another file, I have to create another configuration for that new file. What if I want to debug more 2, 3 files? Do I have to create a new configuration to every single file?
I can also right click a file and then select Debug. It launches in the browser but this way it doesn't stop on the breakpoint (the same breakpoint that it stops in the above example, so both xdebug and chrome extension are working correctly).
It seems that if I right click the file and then select Debug it's creating a temporary configuration but of type 'JavaScript Debug' as can be seen in the following picture:
Then it makes sense it's not stopping in the breakpoint, since it's expecting Java code. Is there any way to change this? Am I missing something?

This is what I do:
Start the debugger and switch to the browser tab that opened. Note that in the browser a query parameter is added to the URL; something like XDEBUG_SESSION_START=15412. From then on, the debugger will be activated by any http request that has this parameter set to this value in $_GET, in $_POST or $_COOKIE. You can also see the right value within the IDE. The debugger tab will have the message Waiting for incoming connection with ide key 15412
Here is the key: after I set my breakpoint in the file I want to debug, I just navigate to it in the browser, but I first add the same query parameter to the url. Easy!

Related

XDEBUG won't step in to functions on different files in PhpStorm and Laravel project

I have the following configuration.
The debugger will only stop at break points in public/index.php
If I put in other files like controller it wont stop.
This is the error I get when trying to step in a function in a different file
UPDATE 1
here is the mapping
I think you looking for remote debugging? If so, you should edit php.ini first:
xdebug.remote_enable = 1
zend_extension=path/to/your/php_xdebug.dll"
Next step, you must add "XDebug extension" for you browser, For example, for Firefox you can install theeasiestxdebug
Next step: restart server to apply XDebug settings, enable plugin in browser, add breakpoint where you need it and enable debug listener in PHPStorm:
and refresh page in browser.

Eclipse Neon php XDebug form action=post in WordPress

Objective: debug a php script triggered from an HTML form with action=POST from within a WordPress Page.
What works: I can initiate a debugging session for index.php. This results in the web page displaying in the browser view. I can then click on any links on the page, which in turn triggers a new call to index.php. I can step through the WordPress code with no problems, set breakpoints and so on.
The apache server is on my workstation, localhost, running Ubuntu Linux.
In one page there is a form. When I click the submit button, I get a message in the browser view saying:
Unable to load page
Problem occurred while loading the URL file:///xyz.php
Error opening file: No such file or directory
It seemed to me that Eclipse is looking for the php file at the workstation root directory instead of the server root. So I put a symbolic link at the root level to the php script to see if Eclipse would find it.
Now when I click on the link I get a File Dialogue asking me do I want to download the php script.
It seems there must be a wrong setting somewhere but I am at a loss. As it stands I can only debug code that is triggered by a GET, not a POST.
If I run the script in Eclipse without debugging, I can post the data and the post script executes. It is only with the debugger that I get the file not found error, so it seems to be in the debugging config:
Server Name: Nip.yt
Base URL: http://nip.yt (127.0.0.1 - works fine in browser)
Document Root: /home/peter/Documents/localhost/html/nip
Path Mapping
Path on Server: /home/peter/Documents/localhost/html/nip
Path in Workspace: /nip
I have tried replacing Path on Server with / with identical results.
Any and all advice appreciated.
EDIT:
I am now using php5.6 with Zend Debugger, but exactly the same thing happens.
Hanging his head rather sheepishly, he says...
I solved the problem. I just put the full URL in the
Doh...
Why didn't I think of that sooner???

PhpStorm debug showing same file twice

I have a simple index.php file set up for debug testing. When I select Run->Debug in the PhpStorm IDE, I see a popup menu that shows the index.php file twice. Debug only works if I select one of them. Does anyone know
Why is it showing twice?
Is there something I can do to make it only show once?
I see there are different icons in the menu, but can't tell what they are or mean...
Right after posting this, I figured it out.
Select the first option in that little menu, Edit Configurations...
Check the box marked Single instance only
Not sure why this works, so if anyone knows, please feel free to comment.
Those are two different debug configs:
First one is JavaScript debug in Google Chrome browser
Second one is "PHP Script" type of config -- to run/debug your php file in CLI environment.
You can check and edit your Run/Debug Configurations via drop down box on main toolbar (next to Run/Debug buttons) or via Run | Edit Configurations....
You will notice there that both of these entries are:
Located under different roots ("JavaScript Debug" and "PHP Script" accordingly)
They are not "permanent" but temporary (icon is faded) which means that they were created automatically by IDE when you choose them for first time (either via context menu or by invoking hot key).

How can I just run a mywebsite/index.php file without Aptana calling remote debugger?

I was expecting, as is the case with Eclipse, that when I run code from the ide, that execution runs until user entry. I shouldn't see debugging occur when I "Run".
With Aptana, when I Run the localhost/index.php file, an annoying remote debug request is called and asks if I want to break on the first line. Often several threads are generated and I'm thrown into a debug perspective. ... despite having set "Never" in Preferences/Run-Debug/"launch in debug mode when workspace contains breakpoints". This seems to only happen with .php files (html files run without debug being called).
"Run Configurations" and "Debug Configurations" appear to be the place to have run and debug operate differently, but they both have Debug options only. e.g. Run Configurations/PHP Web Page/Server -> why does it ask for server debugger? I expect to see this only in "Debug Configurations"
If someone have better solution, Please share.
I had to do a dirty workaround to get rid of the annoying "Path Mapping" from Aptana. I renamed my project's "index.php" to something else and it worked fine. I also added my index_page setting to new url so that it will not affect my project.
This is obviously a noob solution but i cant seem to find any better way to get rid of this.

Opening a local file in Eclipse from the web

Right now, when I notice a problem on a page on my PHP web site, I have to look at the URL, mentally deduce what file is responsible for displaying that page, then navigate the Eclipse PDT file tree to open that file. This is annoying and uses brain power that could have been applied to solving the issue instead.
I would like my PHP web site to display on every page a link that I could click to automatically open the correct file in Eclipse.
I can easily compute the complete absolute path for the file I need to open (for example, open C:/xampp/htdocs/controllers/Foo/Bar.php when visiting /foo/bar), and I can make sure that Eclipse is currently open with the correct project loaded, but I'm stuck on how I can have Firefox/Chrome/IE tell Eclipse to open that specific file.
Edit
I'm going along the way of a data: URI, by adding a link to my file that contains the name of the file, with an unusual MIME type.
<a href="data:link/php;base64,IkM6XHhhb[snip]GhwIgo=">
View controller
</a>
The base64-encoded content is the absolute path to the file on my computer. When I click the link, Firefox lets me bind the content type to a new application, so I chose a batch file I wrote myself:
for /f "delims=" %%i in (%1) do (
notepad.exe "%%i"
)
This works. Now, I would like the file to be opened in the already opened window of Eclipse. What do I have to replace notepad.exe with in the above batch?
[pathtoeclipse]\eclipsec.exe -name Eclipse --launcher.openFile [fullpathtoyourfilehere]
I am not sure if it works with Galileo (i am on Helios)
Further reading: https://bugs.eclipse.org/bugs/show_bug.cgi?id=4922 (it is a long, long story)
I've tried similar things in the past, but this isn't as easy as it should be. The end result was always that Firefox would need an extension to execute a local file (I never found one that would do the job), and IE won't do it at all any more (save, maybe, for some complicated proprietary VBScript/WScript).
I see two workarounds to do this:
A function that displays the file path on your page in a big fat dialog window, making it easy to copy and paste into the Windows + R "Execute" Dialog
Alternatively, registering a custom Protocol (e.g. eclipse://) in your operating system, and tying that protocol to Eclipse. This is a pretty great way actually, I haven't tried this yet but definitely will in the next project I need this. Mozillazine: Register protocol (see the .reg file example)
You get the local path with FILE.
Maybe you try something like this?
<?php
'127.0.0.1' == $_SERVER["REMOTE_ADDR"] and print __FILE__;
?>
Is integrating Eclipse with Xdebug an option? I've done this with TextMate so that generated error messages are clickable to take me to the correct line in the right file. (See this question for details).

Categories