I'm trying to find the "perfect" directory setup for my projects, but I have some difficulties in including Composer resources.
My current project setup:
/ -> base directory
/stuff -> project files that shouldn't be published
/src -> base directory for code
/src/private -> code outside of the public web directory
/src/private/config -> configuration files for web application
/src/private/lib -> PSR-4 root for PHP clases
/src/public -> so-called htdocs (public dir on web server)
/vendor -> managed by Composer
Deployment on web server:
When deploying my project to the webspace I move the project dirs around (with PhpStorm deployment mappings) to fit my needs.
Using the initial project setup, I pull some Composer dependencies which are kept in /vendor.
Then I create /src/public/index.php and just put this in it:
This already leads to a code inspect error: "Path 'vendor/autoload.php' not found."
I tried to play with PhpStorm's PHP include-path, marked directories as resource root or source root, but none of these let me just use "vendor/autoload.php".
I could just rewrite this to
Unfortunately, PhpStorm works fine with this, but after deploying my project to the web server, the path will become invalid because the directory structure is different there.
On the web server I just add my base directory to the include path and 'vendor/autoload.php' works fine, but adding this include path in PhpStorm results in unresolvable classes of composer dependencies.
I also tried to change the location of the "vendor" directory within composer.json to be kept in "/src/private/vendor" but then PhpStorm seems to have a problem with it, so this doesn't seem to be a good idea.
1. I'd really like to know what your setups look like. Do you use a different approach?
2. Let's say we ignore the deployment stuff. How do you include the 'vendor/autoload.php' in your projects to that PhpStorm can resolve the classes?