...

/

Directory Structure Of A Web Application

Directory Structure Of A Web Application

Learn the meaning behind the common directories in most PHP projects.

In this lesson, we’ll learn the directory structure of a typical web application in PHP. Our project will probably look slightly different because frameworks often enforce directory structure conventions. Still, we’ll have something similar to this because although different frameworks assume different directory structures, they have a lot in common. Often the only difference is in the directory names.

Here are the directories we can usually find in the project root:

Press + to interact
bin/
config/
migrations/
public/
└index.php
resources/
src/
test/
var/
vendor/

Let’s see what each of them means.

The src directory

This is a directory for the source code files. Usually, we don’t place source code files in the root directory because it’s already cluttered with tool configs like composer.json and .gitignore. Also, having all the source code files in a single directory makes it easy to configure PSR-4 autoloading.

The test directory

This is the directory with the source code for tests. Having them gathered in a single directory is convenient because it’s easy to filter them out when we don’t need them. For example, we can skip tests when deploying to production. Another example is ignoring tests while searching for class usage in code.

When we split the source code into multiple modules, it’s common to have separate test directories in each module. Also, it makes it much harder to filter out tests. That’s why, even with multiple modules, some prefer to ...