Installing Codeigniter on your local development environment

Click here to visit official Codeigniter download page.

You should see there are several download options made available representing different Codeigniter versions. You should look for the current stable version of the framework. As of this writing, Codeigniter 3.X appears to be the current stable version. Go ahead and click the download button for Codeigniter 3.X. It will download a .zip archive containing the source code for Codeigniter 3.1.5

As per the documentation, Codeigniter 3.X requires a web server running PHP version 5.6 or newer along with MySQL server version 5.1+. So make sure your local WAMP or LAMP stack meets those requirements before proceeding with the installation. You can determine which PHP and MySQL versions are in use by running below script in your browser:

<?php
phpinfo();

Save this script to your web server’s document root and load it in the browser. Once it is loaded look for the PHP version and MySQL version.

Ok. Assuming you meet the minimum requirements, lets proceed with the installation.

Browse to the location where Codeigniter-3.X.zip was downloaded. Then extract/unzip it to the same location. On windows if you have WinRAR or 7zip installed you can just right click on the zip file and choose the relevant extracting option.

On Linux try running below command:

unzip Codeigniter-3.X.zip

If it complains that the ‘unzip’ command is not available, you can install it with below command (Ubuntu):

sudo apt-get install unzip

Now run the unzip command again to extract the zip file

Once you’ve extracted the .zip file, there you’ll have a new directory named ‘Codeigniter-3.X.X’. Now you got to move that directory into your web server’s document root. On windows you can simply copy and paste ‘Codeigniter-3.X.X’ to the server’s document root directory. On Linux you can get it done by executing below command from the shell:

mv Codeigniter-3.X.X /var/www/html/

Note that /var/www/html/ is the document root directory for the Apache server running under Ubuntu 16.04 which is what I am working on for this tutorial. However it may not be the case with your system. So make sure you change it appropriately.

Ok. Once you have moved the ‘Codeigniter-3.X.X’ to your web server’s document root, change the directory name to ‘testapp’. Renaming in windows should be straight forward. If you are on Linux you can do it as follows:

Change Directory to the Apache document root:

cd /var/www/html

Rename Codeigniter-3.X.X to ‘testapp’:

mv Codeigniter-3.X.X testapp

All right. Now its time to configure our application so that we will be able access it from the browser. Browse to the testapp/application/config directory. There should be a file named config.php. This is the main configuration script for our application. Open it with a text editor (For example, Sublime Text or Notepad++) and look for the variable named $config[‘base_url’] which is usually located at the very beginning of the script. Once found you have to set its value to the URL path of your application. In this case, since our application is located at /var/www/html/testapp, the URL path would be http://localhost/testapp/. Check below to see how I have set it:

$config['base_url'] = 'http://localhost/testapp/';

Ok. Finally create new file called ‘.htaccess’ in the ‘testapp’ directory with below contents:

RewriteEngine On
RewriteBase /testapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1

.htaccess is an Apache configuration file, which sets the Base directory of the application to ‘/testapp/’ and instructs Apache to rewrite all the incoming requests to index.php file located at the application root.

Now we are done with the installation. Making sure Apache is running, open your browser and try loading http://localhost/testapp/. You will be greeted with a page saying ‘Welcome to Codeigniter!’

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar



Do NOT follow this link or you will be banned from the site!