Absolute paths not working
I'm having issues with relative paths with certain parts of my test app, including PHPUnit.
For example:
require '../src/ExampleFunctions.php';
I've fixed all issues with absolute paths:
require '/shared/Test/src/ExampleFunctions.php';
All code now runs perfectly OK.
However PhpStorm does not detect the files for functions, classes, etc.
PhpStorm reports:
Path ‘/shared/Test/src/ExampleFunctions.php’ not found
I have setup directory mappings here:
Settings → PHP → Servers
File/Directory
C:\Users\lee\OneDrive\Documents\VirtualBox\debian\Test
Absolute path on the server
/shared/Test
I'm using a Linux server for my code, running PhpStorm on Windows 11.
How do I fix the directory mappings?
Please sign in to leave a comment.
Hello,
Basically, “PHP > Servers” has nothing to do with the “Path not found” in the “Unresolved include” inspection. These mappings are needed for debug to work properly.
As for the situation with absolute paths, especially when you use different file system structures (Windows vs Linux), it is a bit complicated as IDE expects `/shared/Test/src/ExampleFunctions.php` to be available locally so you may navigate to it.
On a Windows machines, IDE treats “/” as root of all your local volumes (f.e. C:\), so you may want to use a workaround here by creating a symlink:
- Create “shared” directory in a volume root (C:\shared);
- Create a symlink inside:
mklink /D Test C:\Users\lee\OneDrive\Documents\VirtualBox\debian\Test
I would not call this workaround elegant but it does the trick and IDE will treat `/shared/Test` as `C:\Users\lee\OneDrive\Documents\VirtualBox\debian\Test` in path recognition.
Hello Vasiliy
Excellent, thank you.
I didn't even know NTFS supported sym links.
I'm trying to solve a similar issue. The IDE will just not find absolute or even relative path with PHP includes.
Example, if you include files as:
/home/dev/project/file.php
But the real path in my case is:
D:\DEV\project\file.php
My project in the IDE as root is:
D:\DEV\project
Can this work in this case as well with a symlink?
I'm using the Windows 11 DEV drive which is D: so moving all my projects to WSL2 is not an option. Is there some solution for Windows to fake, symlink or alias the paths?
The project is deployed to Linux, so the paths are actually correct, but on the development machine it just trows errors everywhere for paths and files it can't find.
I had the impression there was a setting in the IDE to hard-code fixed variables path to trick the IDE into using those paths when it finds them in the code here:
Path variables | IntelliJ IDEA Documentation (jetbrains.com)
But I think that is for an entirely different purpose. I'm surprised anyone else on Windows does not seem to bother about this. For me, it's a big issue since all the variables and code checking is missing since the include files are non-existent for the IDE.
This even creates issues with autoload files as well. There is a new remote option in the IDE which I will try to explore in the future but I guess that involves having all the source code as well on the Linux VM/server? That defeats the purpose of the DEV drive on windows and having all files locally which I need to work with other testing, apps and automations.
There must be some solution on Windows to make the IDE play nice with this, maybe some sort of cygwin path module or addon.