First things first, go to CodeIgniter and download the latest stable version. When setting up the directory structure, I came across another blog (sorry, I’d link it, if I could remember which one it was) that provided a good base layout.
I took the ‘System’ directory and pulled out the ‘Application’ directory from it and placed that in the root of my site. Then renamed ‘System’ to something else, like ‘_codeigniter’ to know it’s not part of my code. I also created an ‘Assets’ directory in the root of my site, and placed my ‘css’, ‘js’, and ‘img’ directories inside there.
Inside your ‘Application’ directory, under the ‘config’ directory open up ‘config.php’.
- Set your ‘base_url’ to your blog url.
- Set ‘index_page’ to empty string, since we’ll be using pretty URLs.
- I also set my Session variables, since I’ll be storing session data in the database. See here for setting up the database sessions table, if you want to do the same.
- For my non-complex site, I also set ‘global_xss_filtering’ to TRUE. You may want to do that on a case by case basis for your site.
Inside your ‘Application’ directory, under the ‘config’ directory open up ‘database.php’. Here you will setup your database related information. This is pretty self-explanatory.
To setup pretty URLs, we’ll be using Apache’s mod_rewrite module. If you’re using Ubuntu, you may need to first enable that module, by running the following command…
sudo a2enmod rewrite
…Then restart apache. If you’re on a web host, most likely ‘.htaccess’ override files are allowed. But, if you’re running your own setup for development and haven’t already allowed for overrides, you will need to tell Apache to allow for them. Inside your Apache virtual host config, you need to change ‘AllowOverRide None’ to ‘AllowOverRide All’, to allow for the use of ‘.htaccess’ files.
For the ‘.htaccess’ file content itself, we’ll be following the CodeIgniter Wiki on mod_rewrite.
- First step is to create a file in the root of your site called ‘.htaccess’.
- Then copy and paste the ‘.htaccess’ code from the wiki page into your ‘.htaccess’ file.
- Now, if you are running on a directory under your web root, which is most likely the case if you are testing on localhost, we’ll need to make a couple changes to the ‘.htaccess’ file.
- If you access your site like, ‘localhost/wurblr.com’, then we’ll make the following changes…
Change RewriteBase line to : RewriteBase /wurblr.com/
Change both RewriteRule lines to : RewriteRule ^(.*)$ /wurblr.com/index.php?/$1 [L]
Your ‘.htaccess’ file should now be setup. Before we test things though, one very important step that made me kick myself for about a half-hour – remove the ‘index.html’ from the root of your site. Otherwise the browser will just try to load that instead of your CodeIgniter site
.
Now, if all went well, we should be able to go to your site’s base URL and see the CodeIgniter welcome code page.