Installation - CodeIgniter
CodeIgniter is a popular, open-source PHP framework used for developing web applications. In this tutorial, we will walk you through the simple and quick installation of CodeIgniter on your local machine.
Prerequisites
Before proceeding with the installation, make sure you have the following installed on your system:
- PHP version 5.6 or higher
- Web Server (like Apache)
- Database (like MySQL)
Steps for Installation
Follow the steps below to install CodeIgniter on your local machine:
Download the latest version of CodeIgniter from the official website: https://codeigniter.com/download
Extract the downloaded file to your Apache server's document root directory. For example, if your Apache server's document root is at
/var/www/html
, extract the contents of the downloaded file to the directory/var/www/html/codeigniter
.Rename the extracted folder to your preferred name. For example, if you want to rename it to "myapp", the path to your application will be
/var/www/html/myapp
.Open the
application/config/config.php
file and set thebase_url
to your preferred URL. For example, if you want to set the base URL tohttp://localhost/myapp/
, the configuration should look like this:$config['base_url'] = 'http://localhost/myapp/';
Open the
application/config/database.php
file and configure your database settings. For example, if you are using MySQL, your configuration should look like this:$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'your_username', 'password' => 'your_password', 'database' => 'your_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 configuring your database settings, go to
http://localhost/myapp/
(replace "myapp" with your application name) in your web browser. This will display the default welcome page of CodeIgniter.To start building your own CodeIgniter application, navigate to
application/controllers
and create a new file. For example, create a new file namedTest.php
and add the following code:<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Test extends CI_Controller { public function index() { echo "Hello, World!"; } }
This creates a new controller named
Test
with a single methodindex
.Now add a new route to the
application/config/routes.php
file, as follows:$route['test'] = 'test';
Go to
http://localhost/myapp/test
in your web browser. This will display the message "Hello, World!".
Congratulations! You have successfully installed and created your first CodeIgniter application.
Conclusion
CodeIgniter is a popular PHP framework used for developing web applications. The installation process is simple and straightforward. By following the steps outlined in this tutorial, you can get started with building your own CodeIgniter application in no time.