Absolute Pathes / Remote Path Outside Scope?

I'm having trouble figuring out the proper way to set up projects in PHPStorm when using a remote SFTP.

My filesystem structure is such on the server:

/ext
  /apps
    /testapp
    /testapp2
  /lib
    /classes

If I want to create a project for /testapp, I'm unsure:

1. What should be the main path in the project?  /, /ext/, /ext/apps/, or /ext/apps/testapp/

2. Which should be my project root and resource root?  I've read through the documentation and I'm still unsure what each does.

3. How do I include/link to /ext/lib/classes?  If I set the main path as anything below /ext/, I can't even see the lib folder.

4. Is there a way to tell PHPStorm what the absolute path is on the server?  If I do a require('/ext/lib/classes/class.php'), it says not found because on the local machine, the path is not the same.

Any help and any or all of these would be greatly appreciated!

2 comments
Comment actions Permalink

Hi John,

When talking about project setup we should consider local location, not remote. But lets assume that local = remote.

1) I would definitely go for /ext/apps/testapp/ as you do not want to include and mix other (sub)projects together (because in case you have the same class names, it will create some issues/inconveniences in PhpStorm)

2) Project root = your "main path in the project". The resource root is needed (at least in current form how it is implemented in PhpStorm) only if your website root differs from project root, for example: project root is "/ext/apps/testapp/", but the actual website root folder is "/ext/apps/testapp/web/" (then all other folders will be outside of website which will give some additional security as it will not be directly accessible via URL). In this case I would mark (well -- I actually DO this in my projects) "/ext/apps/testapp/web/" as resource root.

3) There are three ways of doing this in PhpStorm -- it depends what kind of files are in that "/ext/lib/classes/" folder

  • If those files are some 3rd party libraries (rarely modified) -- you can add them into PhpStorm as External Library (Settings | PHP -- Include path section). Most likely you will not be able to access it remotely via PhpStorm -- in thise case you will have to use other tools/ways to update files there (in theory you should be able to configure such path mapping in your Deployment entry -- try "Add another mapping" on Mappings tab).
  • If those files are actively modified (your own framework etc) then one the below:
    • As additional content root (Settings | Directories) -- it will be part of the project (separate content entry), so it's easier to see what is what. Because I'm not using this myself, I just not 100% sure what needs to be done to be able to access it via built in SFTP support.
    • (the approach I'm using) Make it part of the project itself via symbolic link -- then you can access it as part of the project itself (which means that it should work with SFTP -- I said "should" as SFTP support in PhpStorm has some issues with remote symbolic links, but local symbolic links are working just fine - I'm using it myself). For that create a symlink from within your project that will point to that external location, e.g. "/ext/apps/testapp/lib/classes/ --> /ext/lib/classes/". If you do debugging, you will need to make sure that proper path mappings will be setup in "Settings | PHP | Servers", as PHP debugger (xdebug/zend debugger) work with final/real/resolved paths and not symbolic links (so if you include_once "/ext/apps/testapp/lib/classes/myclass.php", it will include "real" /ext/lib/classes/myclass.php instead). If remote symbolic link will not work for SFTP deployment, then you will need to find another way of uploading such code (separate project for your /ext/lib/classes/ maybe ...)


4) You mean for deployment? If so -- No, as deployment works with relative paths (relative to the home page for that login, of course). For debugging -- yes (Settings | PHP | Mappings), as all paths should be absolute. In any case -- you can always use relative paths instead of hardcoded absolute ... or assemble absolute path at run time (yep, there will be tiny performance penalty, which is almost unnoticeable for average projects - unless it's super busy website when 0.0001ms makes the difference) -- easy to do with single-point entry design (e.g. when all requests are router through single script -- e.g. index.php, where you can define common constants that will be used anywhere in your project)  theeven better approahc -- use class autoloading functionality -- this will allow to load class from anywhere so no more include/require statements (except few cases) -- yep, there will be slight "penalty" compared to direct include/require.

In case I misunderstood your questions -- please provide better explained example/text.

0
Comment actions Permalink

Absolutely fantastic answer.  I wish all my problems were solved in such an informative way!

Thank you!

0

Please sign in to leave a comment.