Working as a freelance developer, I have very little time to waste. To remain competitive, I automated everything possible. This article explains how I setup my working directory for a new project. A bash script which generates the skeleton of new domain (project) is also included.
I do all my development on a Linux desktop because it gives me quick and easy access to the tools I need to automate development. The following structure relies on the use of GIT (SVN would work too) and symbolic links. I'll explain how I use each directory to organize my project.
This is the directory structure:
The public directory could also be called any of the following: public_html, html, http, webdocs, etc. It just depends on how your webhost is setup. If you are not using shared hosting and you have access to your apache config the name of this directory is irrelavnat. I've named it public because it is where my files that are avaiable to the public reside. The core-edits, scripts, sql, bind and apache directories are all private and you don't want them to be publicly available.
I usually install the core CMS or framework I'm using to this directory. The bash script doesn't reflect this it gives you blank directory so you can choose which CMS you want as your base. You can either copy the lib directory or sym link it to public.
Lib (short for library) is where I install all of the CMS/Frameworks I support in a normal work day. The bash script currently install: Joomla, Wordpress, Drupal, OpenCart, MediaWiki, Gallery 3, Mantis, Atrium(Drupal), piwik, vanilla, codeigniter.
All the script does is grab the software from the source website, no configuration or installation is actually done.
Note: I store the whole lib directory to git for easy deployment; however, if you are only using certain CMSes I recommend removing the ones your not using in your first git-commit. (The bash script automatically creates and commits it's setup.)
There always seems to be a situation that requires a core edit to the CMS or framework somewhere during development. A "core edit" is when you have to edit a file that potentially could be lost during the next update. In order to keep maintenance straight forward, when I do a core edit, I copy the file from the lib directory into the core-edit directory then sym link it back to the lib. This will allow me to completely replace (or update) the lib directory and easily maintain/update my changes upon future releases or udpates.
I maintain my sym links in another bash script which I can config.sh and will talk about in a different article.
The scripts directory is where you are going to keep all of your shell scripts. These scripts are all meant to be run from this directory, and you will see me talk about these scripts in my other articles. For example:
This is where I store sql files. The main file stored here would be the database (or databases depending on your requirements) that can be used to restoring the site. The install script also creates a config.sql here based on the domain name you specify.
When switching between development servers, grid servers and Virtual Private Servers I like to keep a copy of my apache2 config files handy. This really only works with Apache 2. Having a copy of my config file allows me to rapidly deploy websites to different servers by using existing deploy scripts.
If your running bind, you can store all the files here to move between servers if required. You could also name this DNS to store your other records (or not use it at all).
Before the script is functional you will have to modify the variables located at the top of the script. You should have both git and svn installed on your system for this script to work.
The script is located on GitHub and you can view it here: github.com/nickyeoman/NYScripts/blob/master/new_project.bash
#To install (on a linux system), just run the following command: wget https://raw.github.com/nickyeoman/NYScripts/master/new_project.bash #then just run bash new_project.bash example.com
I'd like to thank:
Do you know of a better way for me to do this? I'd love to hear from you (@nickyeoman on twitter)