2

I'm trying to configure my server document root into PhpStorm, which is giving an incorrect path to my actual document root (processed by PHP). PhpStorm is detecting $_SERVER['DOCUMENT_ROOT'] in my code and makes a relation to a path that matches with PhpStorm's project but not my actual HTTP server's document root. This is causing a mismatch between actual server's document root and PhpStorm's document root, throwing "path not resolved" warnings.

Is there any way I can set PhpStorm's document root for $_SERVER['DOCUMENT_ROOT'] to resolve?

ProtectedVoid
  • 1,293
  • 3
  • 17
  • 42

3 Answers3

4

PhpStorm has an option to specify path which $_SERVER['DOCUMENT_ROOT'] should resolve to.

Navigate to Languages & Frameworks - PHP - Analysis

See example below (bottom of settings screen) - I've set mine to resolve to www directory in my project

enter image description here

More details could be found on official Jetbrains website https://www.jetbrains.com/help/phpstorm/php.html#include-analysis

xzag
  • 594
  • 3
  • 12
3

Is there any way I can set PhpStorm's document root for $_SERVER['DOCUMENT_ROOT'] to resolve?

Sadly not -- in code $_SERVER['DOCUMENT_ROOT'] is always resolved to the project root folder.

https://youtrack.jetbrains.com/issue/WI-35064 -- watch this ticket (star/vote/comment) to get notified on any progress.


What kind of issues do you have with that? include/require path resolving? If so -- just disable that inspection to get rid of warning. Maybe you should use class autoloading instead (if it's applicable)?

Also: why not try some custom constant that gets defined in entry point script (via __DIR__ usage) -- if you then use it IDE may better resolve the paths.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • Thank you for suggestions, I'll try the workarounds you suggested. I will also follow the ticket waiting for solutions. – ProtectedVoid Feb 06 '18 at 23:03
0

you go in phpstorm->preferences->deployment

you define a deployment (it can be sftp, ftp or other)

then you have on the settings for your deployment a tab that sais "Mapping" that is where you define the mapping between your roots

then phpstorm should resolve your code properly

Nathanael
  • 870
  • 5
  • 11
  • I'm changing my "Local path" in Deployment > Mappings which matched with the value given by PhpStorm on variable `$_SERVER['DOCUMENT_ROOT']` but nothing changes, any ideas? – ProtectedVoid Feb 06 '18 at 20:44
  • no, local path is where your files are, the value given by `$_SERVER['DOCUMENT_ROOT']` is your remote path, not the local path – Nathanael Feb 06 '18 at 20:47
  • Okay, so that just defines a link between local directory and web server directory to view files when opening on browser (I'm developing locally with Nginx), I'm assuming these parameters have nothing to do with PhpStorm setting wrong `$_SERVER['DOCUMENT_ROOT']` then :/ – ProtectedVoid Feb 06 '18 at 20:52
  • so you are deploying locally, I've never done that with phpstorm, but I assume you probably want to set a deployment with your local path identical to your remote path, – Nathanael Feb 06 '18 at 20:57
  • My web server's document root for the site is located in a subfolder of my PhpStorm project. PhpStorm is assuming that my web server's document root is the PhpStorm project root, and that's incorrect in my case. I'm looking the way to tell PhpStorm what's the actual document root so it doesn't throw warnings when including scripts using `$_SERVER['DOCUMENT_ROOT]`. – ProtectedVoid Feb 06 '18 at 21:03