Every other day, I develop new websites from scratch for various clients and sometimes for some of my own projects. Unless the project is really complex, I prefer to develop in CodeIgniter, a super-flexible (MVC) PHP framework which lets me develop super-quick !
It is thus wise to have a standard pattern to follow each time I start a new project. This is what I do -
1. First, the usuals -
- Navigate to Apache’s Document root
- wget latest stable release of CodeIgniter (http://codeigniter.com/download.php)
- Extract
- rename it to MyProjectFolder/
2. Making http://www.myProject.com point to MyProjectFolder -
- Edit the /private/etc/hosts file, add these lines -
# XYZ Project
127.0.0.1 www.MyProject.com
127.0.0.1 MyProject.com
- Edit the .htaccess file in Apache DocumentRoot, add these lines -
# for http://www.MyProject.com
RewriteCond %{HTTP_HOST} ^(www\.)?MyProject\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/MyProjectFolder
RewriteRule ^(.*)$ /MyProjectFolder/$1 [L]
2. Navigate into MyProject and,
- Delete user-guide (un-necessary clutter since it is available online anyway)
- Add readme.md (short project description)
3. Create a folder named static/ within MyProject. This will include all the stylesheets, images, fonts, javascripts etc.
4. Create a .htaccess file within MyProjectFolder/
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt|static)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
This will enable serving static content and also enable clean URLs.
(www.MyProject.com/welcome instead of http://www.MyProject.com/index.php/welcome)
5. Create 3 folders within application/config/ -
- development
- testing
- production
Make sure that ‘ENVIRONMENT’ is set to ‘development’ in MyProjectFolder/index.php
Copy database.php and config.php inside these folders and delete the original one. Then, inside the development folder, setup the development environment -
- Create a mysql database for the project and make changes in config/development/databases.php accordingly
- Create a folder db_scripts inside config folder and keep a record of all sql queries (create table scripts) executed on the database inside this folder.
- Set base_url, encryption key, index_page etc. in config/development/config.php and
- $config['base_url'] = ‘http://www.MyProject.com/’;
- $config['index_page'] = ”;
- $config['encryption_key'] = ‘xxxRandomxxx’;
6. Edit config/routes.php file, set default controller to home (or whatever you wish)
7. Setup logging – Use third party library ci_log4php (This integrates Log4PHP with CodeIgniter)
- Refer my blogpost here for instructions on how to set it up
9. Setup Email (Optional) - Use the default Email helper for internal error-mails, notifications etc. and setup Sendgrid for emails sent to users. (I ll probably cover this in detail in another post)
- UPDATE : Here is the post.
10. Setup Auth – Use a third party library tank_auth [Download]
- Just follow the above link to download tank_auth and simply replace or add all the files and folders it contains.
- The config file is well documented and its easy to customize with a lot of options to set up a logging system exactly as you need
11. Push code to git
- Create a new repo on git and get the url git://github.com/youruser/somename.git
- Create the .gitignore file and select the codeigniter template
- Locally, at the root directory of your source,
git init - git remote add origin <URL From Step 1>
- git pull origin master
- git add .
- git commit -m “First commit”
- git push origin master
Typically the entire process should take around 30-40 minutes :)

Once you’ve done the steps once, you could save time by cloning the base repo for each new project.
One thing though, it’s “CodeIgniter”, no hyphen. The community is actually picky about that, believe it or not. :)
@Casey – True, that would save steps 5 to 10. However, you wont get the latest version of CodeIgniter that way. Gives a good feeling when one downloads the latest one each time :D
@Jack : Point noted, Thank you :)
@Mayank Going on @Casey’s comment, you can link the CodeIgniter repo using the git submodule feature http://git-scm.com/docs/git-submodule so your base project That way you can either have the latest, or a specific branch.
@Rushi : Thanks, this looks interesting, will give it a shot !
Only the system folder changes, so you could just pull that from the git repo each time
whoops! missed Rushi’s comment
Reblogged this on Sam's PHP How-To and commented:
This is a bit over my head but could come in handy!
[...] promised in my previous post, here are the steps to set up email on CI using SendGrid [...]
although CI is a good MVC framework of php
but there is a framework more powerful than CI called Yii (Yes it is); the more reliable and secure
I think that is among the so much important information
for me. And i’m satisfied studying your article. However want to remark on some basic issues, The website taste is ideal, the articles is actually nice : D. Just right job, cheers
It’s an remarkable article in favor of all the online people; they will get benefit from it I am sure.
We are a gaggle of volunteers and starting a new scheme in our community.
Your website provided us with useful information to work on.
You’ve done an impressive task and our entire neighborhood might be thankful to you.