I just finished reading my first book on PHP development. I'm brand new to programming, however not to HTML and CSS.

So, I'm looking to get started on my first application, and my first question is about folder structure on the server and what are the best practices?

When I create static content today, I create one folder per page usually to keep things organized. Any components are included in the related folder, and global components are added to a top level components folder.

I realize the dynamics of PHP will reduce the need for hundreds of pages, and that's why I'm excited to learn this language. However, I still need to keep even the dynamic PHP files and components organized.

I've seen some sites, where people put all their PHP files on the top level folder. Just wanted to get your feedback on how you guys keep your server folder structure organized?

Thanks
Jacob

    What works for you in your situation is the best solution for that situation. 😉

    Take that as you will, but it's truthful. If you're designing an app that has 3 files for inclusion, it really doesn't matter how it's structured. In that case, it's whatever makes it easier.

    If you're creating something that will have more than 20 or so scripts, and each script does something different (like functions, global vars, etc.) then you should probably have a couple directories, one for the application drivers, one for the includes/settings.

    So it's totally situational dependent. If you are working on something small, whatever makes sense to you is the way to go. If you are collaborating on a project, then whatever makes sense in that situation which would be to "refactor" (split up) your files into directories that make sense.

    I'd say some good examples are:
    www.roundcube.net
    [indent]This webmail script is truly amazing in its layout. Javascript is separate from the themes, which is separate from the mail sending which is separate from the mail receiving scripts. Lots of structure. Almost too much in some cases.[/indent]

    www.simplemachines.org
    [indent]This forum project is laid out fairly well. It's got some down spots, but the overall theory is solid. Very easy to navigate, and it just plain makes sense.[/indent]

    www.phpbb.com
    [indent]Another forum software that makes sense. Well laid out, well thought out, and easy to maintain. Lots of separation of scripts so a minor issue can be tracked down quickly.[/indent]

    www.phpsupporttickets.com
    [indent]The free version (1.9) is a good bad example of the way to have your code and scripts. Everything is essentially in a few files, and not really easily trackable. The latest version (2.2 i believe) is a good example to follow too. It separates the GUI from the inner workings, from the templates.[/indent]

    I hope that is somewhat insightful.

      Write a Reply...