I'm trying to figure out the directory structure for a php website.
The website will use:
- a very basic php MVC framework (namely, MinimalMVC, but I'm looking for a generic solution, so the framework can probably be ignored)
- composer to manage PHP dependencies
- SCSS for styling
- gulp to compile the SCSS (for the dev build), and to also minify and concatenate JS and CSS output as well as minify images, etc. (only for deployment build)
- Travis CI for CI stuff
So after a lot of thinking and planning and looking at issues with different kinds of directory structures that I came up with, I still cannot find something that meets my criteria:
gulp deployshould be able to generate a deployment folder, which when put into a/var/www/html/directory on an Apache server, should Just WorkTMNote: MinimalMVC (and also CodeIgniter and other similar frameworks) require their
index.phpfile in the root directory, with anappandsysfolder in the same directorySince the PHP is never really processed by the build process, it would be great if needless copying of the
src/**/*.phpfiles into something likebuild/**/*.phpwas avoidable. Basically, the PHP part does not keep gulp, I'd prefer for it to remain unaffected by gulp.
Now, my thoughts are a little bit of a mess because I've been thinking about this too much, so forgive me for this question being a bit of a mess too, but the basic question is, how should the directory structure look?
An idea:
. |-- composer.json |-- gulpfile.js |-- package.json |-- src | |-- app | | |-- controllers | | |-- models | | `-- <other_framework_stuff> | |-- assets | | |-- css | | |-- img | | |-- js | | `-- raw | | `-- scss | |-- index.php | `-- sys | `-- <framework_stuff> |-- test `-- vendor `-- <composer_stuff> In this structure, the developers only work within the /src directory. The SCSS gets compiled from /src/assets/raw/scss/ to src/assets/css. This way, the PHP remains removed from the build process. When trying to generate a deploy directory, the src folder is copied over, the /src/assets/raw/ (so no /build/assets/raw) directory doesn't exist, and the production/deployment ready CSS, JS and images are found in /build/assets/.
The first problem with this solution is the weird src/assets/raw directory, which seems ugly imho. The second problem is the /vendor directory. This means that the php references stuff from outside src. So if /src/index.php is taking care of it, it would include ../vendor/autoload.php. Then that would mean the same code gets copied over into /build/index.php. And then /build/ won't run by just dropping it into /var/www/html, unless vendor is in /var/www which just seems weird.
There's a lot of other stuff I've thought of, but all of it seems ugly some way or the other. To avoid making this question too long, I'll stop here.
Help, please. Should I just put vendor into /src/ using vendor-dir in composer.json? (I know, eww.) What sort of a directory structure should I use?
composer installin your production server instead.composer installshould not take long when you deploy.Not directly related to your question, but the main thing I would change would be separating what actually gets accessed statically from the web server fromsrc. That will protect you from users trying to directly access php files, which is where many security issues happen. The web server would be configured to access apublicdirectory as the document root. Most frameworks follow that way of setting up.boilerplatedirectory in the root of my app, which contains development assets, likeless,javascripts,bower.json,packages.json,fonts,images, and then I either usegruntorgulpto process them and send them todist/directory.