Setting up Codeigniter

2 minute read

I have been working with (and enjoying) Codeigniter a lot lately it’s a great small, lightweight PHP Web framework.  It’s really good if you are looking for a simple to learn framework that uses the MVC pattern.  The steps below are the things I do to set it up on my local machine to get started on a new project.

  1. Download the latest version of Codeigniter.
  2. Extract the contents of the download file to the desired location where the web site you will be building will be stored (in my example, I am putting this folder in my public_html folder)
  3. Go inside the folder where Codeigniter was extracted to.
  4. The “user_guide” folder contains the documentation for Codeigniter.  If you are new to Codeigniter I would recommend that you keep this folder.  If you are familiar with Codeigniter you can remove this (the user_guide is available online for your reference).
  5. Go into the “system/application/config” folder and edit the $config[‘base_url’] to point to a local web site (example on my machine: http://localhost/~ed/ci).  Save your changes.
  6. Open up your web browser and browse to the location where you have set up the Codeigniter files.  If all is well, you should see a welcome message stating that you have set up Codeigniter!

Removing index.php from URL
When you first start using Codeigniter you will see that the URLs of the system have ‘index.php’ in them.  If you want to remove this file you will need to use the mod_rewrite apache module and create a .htaccess file.  Follow the steps below to accomplish this:

Enable mod_rewrite (this will be different for each Linux distribution, please follow the applicable steps to enable this).   In Ubuntu 10.10 use the following command:

sudo /etc/init.d/apache2 restart

Create a .htaccess at the root of the web site created in the steps referenced above and type in the following:

RewriteEngine On
RewriteBase /~ed/ci_test # this will be different on your site
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index.php|images|robots.txt|css)
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php

Modify the config.php file in the ‘system/application/config’ folder and remove the index.php reference off the $config[‘index_page’] entry.

Save the changes to the file and then go back to your browser and check to see that you can view your Codeigniter welcome page without the index.php file!  If all goes well, you should see the same Welcome page that you saw when you first set up the web page.

After setting up Codeigniter, I would highly recommend that you read the user guide as this will give you a good idea of how Codeigniter works.  The documentation is great as it’s very concise and easy to go thru.

Leave a comment