At Agira, Technology Simplified, Innovation Delivered, and Empowering Business is what we are passionate about. We always strive to build solutions that boost your productivity.

,

Install & Configure The CodeIgniter On Ubuntu 16.04.

  • By Allan Watts
  • September 26, 2018
  • 4711 Views

While developing web Application we ought to spend lot of time on writing the same code again and again, So working with frameworks likely to reduce our risk factor and definitely will make our work easy. On bright side, We know that CodeIgniter is one of the best PHP driven framework which is helping us to ease our work. Due to some cool features of CodeIgniter like simple interface, libraries, and logical structure to access the libraries, plug-ins, helpers and some other resources which resolves the complex functions of PHP to maintain the high performance. Even it simplifies the PHP code and help us to bring out the fully interactive, dynamic website in short time. So today, am planning to tell you guys how to install codeigniter application on Ubuntu 16.04 and also will cover up complete configuration part.

Support It Extends:

  • CodeIgniter support PHP 5.2.6 or nearer version,
  • CodeIgniter support MYSQL 4.1 or nearer version,

 

Advantage of using this framework:

  • Light Weight frame work.
  • Model-View-Controller Based System.
  • High Performance.
  • Easy code structure.
  • Form and Data Validation.
  • Support image manipulation, etc.

Steps To Install CodeIgniter:


First navigate to our Apache root folder:

  • cd /var/www/html

Download the CodeIgniter stable release from

Extract the downloaded file:
After downloading the zip file, just extract it.

  • unzip 3.1.5.zip

While extracting the file if you face any problem just check the unzip whether it’s installed or not.
In case if you found it not installed then use the below command to install,

sudo apt-get install unzip

 
Now will continue with the extracting process. After running all the above commands, if you like to rename the Codegniter then look for the new directory which is named as codeigniter along with its version. Similarly here it is named as CodeIgniter-3.1.5 and so am just renaming the directory CodeIgniter 3.1.5. into CodeIgniter likewise you can name it as you wish.
Follow this command to rename it,

mv CodeIgniter-3.1.5 codeigniter

 
Once the CodeIgniter is successfully installed. you need to set the virtual host in Apache. For that, refer this url to set the virtual host in apache: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
Once everything is set, we should do some basic configuration. if you’re planning to use db then you should do some basic modification in database.php. This database file will be located at “application/config/database.php”

$db['default'] = array(
       'dsn' => '',
       'hostname' => 'localhost',
       'username' => '',
       'password' => '',
       'database' => '',
       'dbdriver' => 'mysqli',
       'dbprefix' => '',
       'pconnect' => FALSE,
       'db_debug' => (ENVIRONMENT !== 'production'),
       'cache_on' => FALSE,
       'cachedir' => '',
       'char_set' => 'utf8',
       'dbcollat' => 'utf8_general_ci',
       'swap_pre' => '',
       'encrypt' => FALSE,
       'compress' => FALSE,
       'stricton' => FALSE,
       'failover' => array(),
       'save_queries' => TRUE
);

After completing the configuration, now save and exit the file.

Tips Of The Day: How To Embed The JW Player Into Website

 

Defining The URL Structure Of Codeigniter

One of advantage of this CI URL is, that it will have a segment based structure which is more easy for us to understand as you can notice on this link,http://project.com/jwplayer/index.php/controller/method/parameter

controller — segment represents a Controller Class located at application/controllers;
method –represents the function located in a class
parameter— represents parameter passed to the method in a class
Use this to pass the simple parameter,

 function myCustomfun($name="Allan"){
 echo "Hi".$name;
   }

 

Steps To Remove Index.php from Url in Codeigniter

Basically the CI url loads the index.php by default and in case if you want to remove the index.php from the url then we should follow the below two 2 steps,

  1. Enable mod_rewrite
  2. Add .htaccess file in your application.

 

1) Enable mod_rewrite

Before doing anything, first check is the mod_rewrite is enabled are not and incase if not then you use the following command to check it out.

apache2ctl -M

 
If you found Rewrite_module on the list then its fine you can simply leave it but if its not got enabled then we should enable it by using the following command.

 a2enmod rewrite

 

Now we must restart the Apache server to reflect the changes, use the below command to restart the apache,

sudo service apache2 restart

 

2) Add .htaccess file


we have almost done with it and now we just have to add the .htacess file in our application. Add .htaccess file at /var/www/html/codeigniter/ and copy & paste the following content in .htaccess file

   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule .* index.php?/$0 [PT,L]

 

Best To Read: CRUD operation on Google Spreadsheet using NodeJS


Then we should check the .htaccess file is enabled in Apache config settings or not. and enable to that, set the virtual host file in following way,

<Directory /var/www/>
       Options Indexes FollowSymLinks
       AllowOverride All
       Require all granted
       Order allow,deny
       allow from all
</Directory>

 
OK guys we’re just one step away to finish it, now look for the config file which is located at “application/config/config.php”
And find the following code,

$config['index_page'] = 'index.php';

 
And replace it with this.

$config['index_page'] = '';

 
Once you done with the above procedure then immediately the index.php file will be removed and the url will look like this,
http://project.com/jwplayer/video-upload
Yes! we have successfully installed and configured the CodeIgniter Application on Ubuntu 16.04 and now its your turn so just give a try and let us know your experience and queries in the comment box, will surely help you out. parallely, don’t forget to subscribe us to get more blogs & latest updates on your favorite frameworks and from diverse technologies.
For any queries reach us via info@agiratech.com.

Allan Watts

An active software developer with “Can Do” attitude. Around 3.5 years of experience, Allan developing skills in php that allows him to craft flawless web applications in Symfony, Laravel, CodeIgniter, Javascript & WordPress. Also the most accompanied developer for building applications from designer perceptive