I am new to PHP and want to know the directory structure for the php projects. I have experience in Java and in java we have src contains java source files, WEB-INF contains lib
For a library, I am using the following structure... plus i've included recommendations I'm not using (yet)
PROJECT ROOT
|--composer.json
|--README.md
|--docs //for documentation files
|--tests //for Unit Tests
|--vendor //for external libraries (if everything isn't included through composer)
|--examples //examples of the library being used
|--config //any configuration files you may have
|--src //where the library's actual code "lives"
|--php //php source code, classes, any other scripts
|--View //html views, but actually php files that output html
|--Style //contains .css files
|--Script //contains .js files
|--Res //contains other deliverable resource files. Could be mp3 files, json etc
Currently, I'm only using composer.json
,README.md
, and src
among the root files. But I will probably use the others as I've described, when i get to that point.
By no means do I think this is "correct". And this setup only works because I have a php router on every request. With a .htaccess
, you could route a .css
file to /src/Style/requested_file.css
.
I wanted the project root to be cleaned up, and I have achieved that. PHP Fig does not have a PSR for directory structures... that I'm aware of. I had hoped PSR-4, autoloader would have had some standards, but... not really, in regard to directory structure.
You could look at laravel, wordpress, PHP Mailer and other php libraries to see examples and see what you might like best