Skip to content

Keeping your web server organized

Why organize your web server?

We have all been there, in a rush to get the job done, throwing up test scripts and images, it doesn’t take long before your directories get cluttered, often times with useless files that haven’t been used in years. Some of you out there, like me, have even walked in to companies only to find that your predecessor was completely incompetent and left the server in total disarray.

If this has happened to you, than stick around you may be able to relate to the best practices I will describe and probably thank me a year from now when you need to find something on your server.

Typical files on a webserver

Most websites will contain 100′s of images, swfs, flvs, xml, html, php/asp/etc.. files. Below you will find an example of how you may layout your directory structure.


Document Root: /var/www/sites/mysite/

Folder Name: Assets
What are assets? Assets, are files that are utilized by the “view”, or rendered page. Assets may include but not limited to CSS, SWF, XML, Images and Javascript files. An example layout might look like:

Some people may argue that adding “assets” is uncessarily contributing to the filesize of a webpage, although this is true, the increase is negligible. Now, anyone in your company can easily browse the file structure and locate files associated with the rendering of your “view”.


Having adequate file structures in place to support your non-compiled scripts will absolutely alleviate future headaches associated with supporting old code. Here I will briefly discuss the folder structure that I utilize for my PHP work.

Since PHP 5 was released, I have moved to an MVC style of programming and I utilize the __autoload feature of PHP almost exclusively. This requires that I have a well organized file structure.

A typical structure of mine may look something like this:

My classes directory will hold all parent classes which will get autoloaded by my controller. The includes folder stores all files that will be implicitly called via “include” or “require”. The models directory hold all my model code, and the views directory hold all my presentation scripts.

Taking it one step further. Within these folder structures I include descriptive sub folders, so that 6 months from the time i place files in those folders I will easily be able to determine their contents.

Let’s take a file manager script for instance. I would place this file in the classes directory, and it will look something like this.

The class name of the manager looks like: File_Manager

class File_Manager {
     //do something relating to file management

The autoload function looks something like this.

function __autoload($class) {
    require _DOCROOT_. "/classes/". str_replace("_","/",$class) .".php";

Posted in Web Development.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK


(required, but never shared)

or, reply to this post via trackback.