codeigniter
  1. codeigniter-installation

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:

  1. Download the latest version of CodeIgniter from the official website: https://codeigniter.com/download

  2. 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.

  3. 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.

  4. Open the application/config/config.php file and set the base_url to your preferred URL. For example, if you want to set the base URL to http://localhost/myapp/, the configuration should look like this:

    $config['base_url'] = 'http://localhost/myapp/';
    
  5. 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
    );
    
  6. 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.

  7. To start building your own CodeIgniter application, navigate to application/controllers and create a new file. For example, create a new file named Test.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 method index.

  8. Now add a new route to the application/config/routes.php file, as follows:

    $route['test'] = 'test';
    
  9. 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.

Published on: