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

Hi,

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:
/home/user/Documents/Workspace/MyProject

Host:
http://myproject.dev/

Document root:
/home/user/Documents/Workspace/MyProject/application/web/

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.

11 comments

This seems to be somewhat related to my problem: http://youtrack.jetbrains.com/issue/WI-11672

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...

0

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?

0

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.

0

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

The problem I encounter is that

$_SERVER['DOCUMENT_ROOT']

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:
/home/user/Documents/Workspace/MyProject

Host:
http://local.myproject.com/

Document root:
/home/user/Documents/Workspace/MyProject/public_html

example: result of $_SERVER['DOCUMENT_ROOT'] + '/index.php:
/home/user/Documents/Workspace/MyProject/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

0

@Info

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)

 

0

In the next screenshot the error shows up (works perfectly on the server though).
The 'europlanint.com' is my project folder. In Mamp Pro 'local.europlanint.com' 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.

0

BTW, the resource folder works fine.

Only $_SERVER['DOCUMENT_ROOT'] fails

0

$_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. http://stackoverflow.com/a/42076139/783119 ). 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).

0

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).

 

0

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

 

0

Please sign in to leave a comment.