Skip to content
Advertisement

Project structure for PHP

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, and jsp pages. Do we have any similar standard directory structure in PHP? Also do we have layering in php like we have layers in java (e.g. Web, Service, DAO layers)

I browsed few links. But every one giving different answers.

Not sure if we can compare the two languages. I just want to stick to some standards.

Thanks in advance.

Advertisement

Answer

Nope. PHP is what you make of it. It can be very simple flat files, or however you want it.

That being said, there are a few agreed upon coding standards, but there is no “enforcement” of said standards. They are called PSR (PHP Standards Recommendation). There is a background on it here: http://net.tutsplus.com/tutorials/php/psr-huh/
You can view the standards one by one here: http://www.php-fig.org/psr/

Most major frameworks follow these standards, and if you are going to use one, it may be easier to go with the flow.

Again, every framework, project, plugin, program, etc, have different layouts with different project structures. A common structure is something like this:

-framework_dir
-public_html
    -js
    -img
    -css
    -index.php
    -protected/private
        -controllers
        -models
        -views
        -etc

They then use the .htaccess file to block access to the protected directories. Again, this is just the common representation I have seen in several frameworks. If you are doing a personal project, just use something that is comfortable to you. Every framework is going to give you a different library or way to access the data. There are no “layers”, but again every framework has objects that handle different areas (email, database, cache, http, logs, etc). Because there are dozens of popular ones, it is just up to you to find what fits with your philosophy or project. Watch a few of the 5 minute blog videos, see what jives, and then give it a test run for a couple days. If you don’t like it, switch to another.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement