PHP
  Home arrow PHP arrow Page 2 - PHP Application Development Part One
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP Application Development Part One
By: David Fells
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 92
    2005-03-01


    Table of Contents:
  • PHP Application Development Part One
  • Directory structure
  • File naming conventions
  • Coding conventions
  • PHP coding conventions
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    PHP Application Development Part One - Directory structure
    ( Page 2 of 6 )



    Directory structure and filesystem naming conventions are something that rarely receive enough attention in PHP applications. It is common practice to simply begin work and save all project files to a publicly accessible Web directory, despite the fact that many PHP files, especially configuration files and files uploaded through the application itself, never need to be directly accessed via the Web. It is also common to see files of all types – configuration files, function libraries, class files, logs, and so forth all mixed in the main application directory or all stuffed into one subdirectory.

    In addition to this, files of all kinds tend to have haphazard names that often do not adequately convey the purpose of the file – a problem that is compounded when the files do not live in a directory that conveys the general purpose of a group of files. As a project grows, something seemingly insignificant like a bit of filesystem disorganization can become a maintenance nightmare.

    It is important to organize your project files, period. Directories should have names that are meaningful and should be in the appropriate location. The image below is an example of what a basic PHP Web application directory structure should look like. Images used in this article will be captured in Windows but do not rely on any operating system specific features or system directories.

     

    In this example, “public_html” is the Web accessible directory and “webapp” is our project directory. On Red Hat this might be “/home/webapp/”. The “public_html” directory (the default name for the web directory in Red Hat) will contain files a user would directly access in a Web browser, such as “index.php”. In this directory you would organize your css files, javascript files, and images into the appropriate directories. These files must be in the Web accessible directory since browsers need access to them.

    The parent directory, “webapp”, is where all files that do not need to be accessed by a Web browser will reside. The “classes” directory will be used to store class files, the “config” directory will store configuration files, “lib” will store files containing function libraries, “logs” will contain our applications custom log files, and “templates” will be the directory where we store our HTML template files.

    The names of these directories are clear and meaningful and reside in the proper locations. In a product intended for repeat use, files outside of the public Web directory would be stored in a centralized location on the server and accessed by project scripts at that location either directly or by creating symbolic links (shortcuts in Windows) to those directories.

    There are some simple security considerations when planning your Web applications directory structure, one of which we addressed above – keeping files out of the Web accessible directory if they aren’t accessed via the Web. Other simple considerations include preventing directory listings, blocking hotlinking, and password protecting areas that require a login through .htaccess files (or IIS Virtual Directory configuration). Authentication through .htaccess files uses basic HTTP authentication and is only one possible method of requiring authentication on a directory.



     
     
    >>> More PHP Articles          >>> More By David Fells
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT