How to set up local server where document root is under project root?


My PhpStorm project marks several file paths as invalid because I am not able to set up web server mappings correctly.

These are mainly static file references such as images in templates and CSS files.

Here is a setup that is similar to the problem I am facing:

Project root:


Document root:

As per the documentation, this is:

  • obviously not where I can use a remote server configuration;
  • not an in-place environment, as the document root is not parent of the project root;
  • not a local server configuration, as I don't want to copy anything -- the files are all in place.

Therefore I think I'm out of options, but I hardly can believe that this is a so special setup that PhpStorm wouldn't support it: a project that doesn't want to expose all of its files to the web server, but still wants to be tested locally.
Note: I don't really want to use the 'run' functionality in PhpStorm, so that is not necessary. My project is running fine with the locally installed development environment. I just would like PhpStorm to provide autocompletion to static files as well, and not mark them as invalid (as they are not invalid).

Any advice would be much appreciated.


This seems to be somewhat related to my problem:

By setting the web directory as resource root I now have autocomplete and static files are not marked as invalid in template and css files. However thet are still marked as invalid in SCSS files...


Can you be more specific, please? Do you mean that the SASS partials can't be resolved by path specified in @import? Or? Did you set the path related to your web root? What do these paths look like?


No, SASS partials were actually resolved correctly. Static files such as images were marked as invalid. Code completion worked, though, so I invalidated caches and restarted phpStorm which seemed to help this issue.


I have a very similar setup and I don't think it's uncommon.

The problem I encounter is that


outputs the project root and not the document root, which results in a lot of unresolved path errors in PHPStorm.
Very anyoing and I have no clue how to fix this.


More details about my setup:

Project root:


Document root:

example: result of $_SERVER['DOCUMENT_ROOT'] + '/index.php:

As you can see, PHPStorm leaves out the public_html folder from the path and therefor cannot find the requested file.
This is no problem on the local server / webserver, only in PHPStorm.

How can I solve this?


System: OSX 10.11.6
Local server: Mamp Pro 3.5



Please specify where the issue happens exactly -- it's not clear from your description that you have provided so far. Some screenshots are welcome.

For resolving web path (for web resources) marking that folder (public_html) as Resource Root should do the job (does here).


>I have a very similar setup and I don't think it's uncommon.

That's true -- I'm also using a subfolder ("httpdocs" or "web" in most cases) as website root.

Works fine for me in PhpStorm when resolving paths to web resources (css/js/images).

I do not really use include/require in PHP (class autoloading via Composer or own autoloader does all the job .. so have only 1 require statement in the project in a bootstrap file). If you are using something like require $_SERVER['DOCUMENT_ROOT'] + '/index.php'; then yes -- from IDE point of view it will not always work as PhpStorm resolves $_SERVER['DOCUMENT_ROOT'] to project root.

If you have single entry point script (e.g. all requests go trough index.php file) then you can define constant there and then use them everywhere in the project, something like this:

define('DIR_WEB', __DIR__); // web root (PROJECT_ROOT/public_html)
define('DIR_ROOT', dirname(__DIR__)); // site/project root (PROJECT_ROOT)
define('DIR_VAR', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'var'); // temp folder (PROJECT_ROOT/var)
define('DIR_APP', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'app'); // app folder (PROJECT_ROOT/app)



In the next screenshot the error shows up (works perfectly on the server though).
The '' is my project folder. In Mamp Pro '' is forwarded to the 'public_html' folder within this project folder

My directory settings in PHPStorm:

And my deployment settings:

Within the project I need access to files a level above the root (public_html) folder.


BTW, the resource folder works fine.



$_SERVER['DOCUMENT_ROOT'] is always resolved into project root by PhpStorm. There are no options to change that for your include/require statements ATM -- you may only write your code slightly different (see my previous comment) if that's possible.

Otherwise -- consider disabling that particular inspection so it does not show warnings (e.g. ). If you need some Ctrl+Click navigation -- consider installing Navigate From Literal plugin (not ideal in some situations (works based on file name part only and ignores the rest of the path .. so may show multiple targets in rather exact-match situations) but still better than nothing).


Any change this behaviour can be adjusted in an update, just like the resource root works?
I can hardly imagine this would take a lot of work.

Not only I value the live error reporting a lot (which is now cluttered with false reports), but it also prevents the use of the autocomplete functions.
Right now, all paths and files have to be manually entered and checked (and rechecked after changing the directory structure).



It would be better to submit a corresponding feature request/usability issue at our tracker.



Please sign in to leave a comment.