xDebug with virtual hosts; how to configure?

Hi,

I have a local apache2 server running with virtual hosts for each of my projects, ie. http://project1, http://project2. The virtual host root file path might be something like /media/user/project1/public/html/. Some of these projects use symlinks, too. So an Url like http://project1/app might point to a directory that lives above the virtual host root dir, ie. /media/user/project1/app/.

How exactly am I supposed to configure PHPStorm now to debug project1? I was using the Web Server Debug Validation, but am unsure what to enter there. I can get the validator to succeed by either using http://localhost or http://project1, but when I set a breakpoint in the IDE and activate my browser debug helper, it just runs through without stopping. When I manually set a xdebug_break() instead of a breakpoint, it seems to work.

I do get the error "..is not mapped to any file in path project", but when I try to resolve the mapping issue, I basically can select any file or folder from the project, but the OK button stays greyed out.

So much for the "Zero Configuration", I guess. Any help would be appreciated.

6 comments
Comment actions Permalink

Hi there,

"Settings/Preferences | Languages & Frameworks | PHP | Servers" -- path mappings are configured there.

>So an Url like http://project1/app might point to a directory that lives above the virtual host root dir, ie. /media/user/project1/app/.

If "app" in "//project1/app" is a real folder/symlink (both are real nodes in a file system) then that's what path mapping is for. Since the actual path file be outside of the project root, then it needs to be included in a project as "PHP Include path" entry ("Settings/Preferences | Languages & Frameworks | PHP").

0
Comment actions Permalink

Thanks, but that doesn't really clear things up.
When I get the dialogue "Incoming Connection from XDebug", I can only choose from files within my PHPStorm projects path. But for that particular URL, there is no file - it's WordPress, an Url like http://project/pagename doesn't have a file path. So I figured I would just select the WP base bath, but it won't let me. My PHPstorm project root is wp-content, not the WP base path.

0
Comment actions Permalink

>But for that particular URL, there is no file - it's WordPress, an Url like http://project/pagename doesn't have a file path.

Yes .. but it's handled by some PHP script (usually index.php in WordPress). Plus, IDE should show the script that got executed when debugging session has started.

>Also, my PHPstorm project root is wp-content, not the WP base path.

That might be an issue.

In those few WP projects that I had to work with, I have used whole installation and had no issues with debugging.

I cannot give precise advise on how it can be solved with such setup (when your project cover only half of the actual code base). It could be the aforementioned PHP Include paths .. but "wp_content" would be a child for such folder ...

If you want to debug something (e.g.part of some bigger project) , you need all main files that will be executed along the path.

Possible alternative (not 100% sure though): do not do actual debugging mode (zero config or from within the IDE) but try using xdebug_break(); in actual code (programatic breakpoint). In this case debug session will be attempted to setup in the middle of execution .. so may not require access to index.php (that is outside of the project).

0
Comment actions Permalink

I made a new PHPStorm project where the project root was the WP base path. Then I was able to map files correctly. I usually made wp-content my project root to reduce noise, because there is no development happening outside of this folder. So I'm a bit surprised that xdebug or PHPStorm need a certain project file/folder structure, basically expecting that my virtual hosts map 1:1 to my project folders.

0
Comment actions Permalink

>So I'm a bit surprised that xdebug or PHPStorm expect a certain project file/folder structure.

It's not. But .. when debug session is established (which is usually happens at the first script that gets executed -- index.php) xdebug tells that "I'm executing/debugging index.php" .. and IDE needs to know what script that would be. If you do not have it in your project, and it is not referenced in any other way .. then IDE may not be able to step in into that code etc (IDE does not index non-project files or files marked as plain text/unknown type)..

That's why having whole website code (well, that gets executed along the path) in the project is the best thing to have.

Anyway: https://confluence.jetbrains.com/display/PhpStorm/WordPress+Development+using+PhpStorm -- maybe it can be done differently. I have never tried it as I'm always working with the whole site.

0
Comment actions Permalink

So if my team is working on an app with 100'000 files, but I'm only working on a small submodule - according to that info, I would still need to have the entire app in my project if I want to use xdebug? I see the necessity, but I would think there should be another solution.

0

Please sign in to leave a comment.