Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

      June 1, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

      June 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to Develop with CodeIgniter on Ubuntu – Step-by-Step Environment Setup

    How to Develop with CodeIgniter on Ubuntu – Step-by-Step Environment Setup

    January 24, 2025

    CodeIgniter is a popular open-source PHP framework you can use to build dynamic and robust web applications. It’s simple to use, fast, and flexible. This makes it a good option for any developer who wants to have a light yet powerful framework that will let them prototype or develop scalable applications fast.

    Also, CodeIgnitor’s MVC (Model-View-Controller) architecture makes the process of organizing code and separating business logic from the user interface a piece of cake, yielding cleaner and maintainable projects.

    Whether you’re building a small website or a complex application, CodeIgniter has a bunch of tools, libraries, and helpers that make the development process easier. They help you handle common tasks like database queries, session management, and form validation. Many devs love this tool because of its ease of use, making it an ideal framework for both beginners and experienced coders.

    In this guide, I’ll walk you through the process of configuring CodeIgniter step by step, ensuring that you have a fully functional setup for your project on your local development environment.

    Prerequisites

    Before getting started, make sure you meet the following requirements:

    • Basic Knowledge of PHP: Understanding PHP syntax and basic programming concepts will help you follow along more easily.

    • Web Server (for example, Apache or NGINX): CodeIgniter needs a server to run. Make sure you have a working server set up on your local machine or hosting environment.

    • PHP Installed: You’ll need PHP 7.3 or higher (depending on the version of CodeIgniter you’re using).

    • Database System: CodeIgniter supports several databases, but MySQL is the most commonly used. Make sure you have access to a database system and know its credentials.

    • CodeIgniter Download: Download the latest version of CodeIgniter from the official website, GitHub repository, or use composer to install it.

    How to Use Composer to Install CodeIgniter

    Now that you understand the prerequisites and have everything set up, let’s move on to installing CodeIgniter. One of the easiest and most efficient ways to install CodeIgniter is by using Composer, a popular dependency management tool for PHP. In this section, I’ll guide you through the steps to install CodeIgniter using Composer.

    First, create a new directory using mkdir my_project then navigate to the directory using cd my_project. Run the following Composer command to install CodeIgniter. You can specify the version you want (e.g., ^4.0 for the latest version of CodeIgniter 4).

    composer create-project codeigniter4/appstarter .
    

    This command will download and install the latest version of CodeIgniter 4 and set up the project for you:

    CodeIgnitor download via composer output.

    After the installation is complete, you should see the CodeIgniter project structure in your directory. To check if everything is working, you can start the built-in PHP server by running:

    php spark serve
    

    Output:

    Php spark serve output.

    Then, open your browser and go to http://localhost:8080. You should see the CodeIgniter welcome page.

    CodeIgnitor welcome page.

    How to Install CodeIgniter Manually

    If you prefer not to use Composer, or if you’re working in an environment where Composer isn’t available, you can manually install CodeIgniter. This method involves downloading the framework files directly and setting up your project manually. While it requires a few more steps than using Composer, it’s still straightforward and gives you full control over the installation process.

    In this section, I’ll walk you through the steps to manually install CodeIgniter and configure it for your project.

    Download via Git:

    cd /var/www/html
    sudo git clone https://github.com/bcit-ci/CodeIgniter.git codeigniter
    

    Or download as ZIP (from CodeIgniter official website): Download here. Extract it in /var/www/html. Whereby you can do so using the terminal or UI.

    Extracting the ZIP File via the UI:

    If you’re not comfortable using command-line tools, you can easily extract the ZIP file using your computer’s graphical interface. Here’s how:

    Click on files/Other Locations/computer to access /var/www/html. Copy the .Zip file you downloaded earlier in the created folder and right click. Then click on extract here to unzip it.

    ZIP Extraction image.

    Extracting the ZIP File via the Terminal:

    If you’re comfortable using the command line, you can extract the CodeIgniter ZIP file directly via the terminal. This method is especially useful for Linux and macOS users or if you’re working on a remote server without a graphical user interface.

    First, ensure you have unzip installed on your Ubuntu system:

    sudo apt update
    sudo apt install unzip
    

    Check your permissions to ensure that you have the necessary access to the /var/www/html directory. If needed, use sudo for administrative privileges.

    Steps to Extract the File

    Assuming your uploaded file is currently located in downloads/data…, move it to /var/www/html:

    sudo mv /mnt/data/CodeIgniter.zip /var/www/html
    

    Navigate to the /var/www/htmldirectory:

    cd /var/www/html
    

    Extract the ZIP file by using the unzip command to extract the contents:

    sudo unzip CodeIgniter.zip
    

    After extracting, set the correct ownership and permissions for web server access:

    sudo chown -R www-data:www-data /var/www/html
    sudo chmod -R 755 /var/www/html
    
    • www-data (first part) → The user.

    • www-data (second part) → The group.

    Extracted folder(Codeigniter-develop) image.

    change Codeigniter-develop /bcit-ci-CodeIgniter-bcb17eb/….folder name to just codeigniter

    Verify Extraction

    Visit your web server’s URL (for example, http://localhost) to check if the contents are correctly deployed.

    Set Folder Permissions

    After installing CodeIgniter, make sure you have the correct permissions for your directories, particularly writable and cache directories. This ensures that CodeIgniter can write logs, cache files, and session data.

    Run the following commands to set the correct permissions:

    sudo chmod -R 755 /var/www/html/codeigniter
    

    Configure the Base URL

    The base URL for your project needs to be set up in application/config/config.php.

    Open the config.php file:

    sudo nano /var/www/html/codeigniter/application/config/config.php
    

    Output:

    Config.php terminal image.

    Set the base_url as follows:

    $config['base_url'] = 'http://your-domain-or-ip/';
    

    Replace http://your-domain-or-ip/ with your actual domain or IP address where the project will be accessible.

    After making changes:

    • Save the file: Press Ctrl + O (Write Out).

    • Confirm the filename: Press Enter.

    • Exit the editor: Press Ctrl + X.

    💡
    You can also edit the files using UI by accessing them from Other Locations//var/www/html/codeigniter

    Configure the Database (if Applicable)

    If your project uses a database, you’ll need to set up the database configuration in application/config/database.php.

    To do this, open the database configuration file:

    sudo nano /var/www/html/codeigniter/application/config/database.php
    

    Configure the database connection by setting the following options:

    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'your-db-username',
        'password' => 'your-db-password',
        'database' => 'your-database-name',
        '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
    );
    

    Replace your-db-username, your-db-password, and your-database-name with your actual database credentials.

    Set the Environment

    CodeIgniter uses the environment setting to load different configuration files depending on the environment (for example, development, production).

    To set the environment, open the index.php file in the root directory of your project:

    sudo nano /var/www/html/codeigniter/index.php
    

    Locate the following line:

    define('ENVIRONMENT', 'development');
    

    You can set it to production, testing, or development depending on your setup. For development, it should be set to development

    Autoload Libraries, Helpers, or Config Files

    You can specify which libraries, helpers, or config files to autoload in application/config/autoload.php. Open the autoload configuration file:

    sudo nano /var/www/html/codeigniter/application/config/autoload.php
    

    Modify the autoload array to load commonly used libraries and helpers:

    $autoload['libraries'] = array('database', 'session', 'form_validation');
    $autoload['helper'] = array('url', 'file');
    

    Enable Mod Rewrite (For Clean URLs)

    If you want clean URLs, you need to enable mod_rewrite on Apache. Edit the Apache configuration file as follows:

    sudo nano /etc/apache2/sites-available/000-default.conf
    

    Ensure that the AllowOverride directive is set to All in the <Directory> section:

    <Directory /var/www/html>
        AllowOverride All
    </Directory>
    

    Enable mod_rewrite and restart Apache:

    sudo a2enmod rewrite
    sudo systemctl restart apache2
    

    Verify CodeIgniter Directory Placement

    If CodeIgniter is not in /opt/lampp/htdocs, move it there:

    sudo mv /var/www/html/codeigniter /opt/lampp/htdocs/
    

    Test CodeIgniter

    Open your web browser and navigate to the base URL (http://your-domain-or-ip). You should see the default CodeIgniter welcome page if everything is set up correctly:

    CodeIgniter welcome page.

    Run curl ifconfig.me to find your public IP. If you’re hosting CodeIgniter on a local machine (for example, in your home network), use the following command to check your local IP: hostname -I.

    Troubleshooting

    If you encounter any issues while setting up CodeIgniter, here are some common problems and how to resolve them:

    Set CodeIgniter as the Default App

    If you want CodeIgniter to load as the default app (instead of the XAMPP landing page if you have XAMPP installed), remove or rename the default index.php in the htdocs directory:

    sudo mv /opt/lampp/htdocs/index.php /opt/lampp/htdocs/index.php.bak
    

    Move the CodeIgniter files to the root of the htdocs folder:

    sudo mv /opt/lampp/htdocs/codeigniter/* /opt/lampp/htdocs/
    

    Restart Apache

    After making changes, restart Apache to apply the configuration:

    sudo /opt/lampp/lampp restart
    

    Creating a Controller

    To start developing your application, you can create a controller to handle requests.

    Application folders.

    Create a new controller in application/controllers/ like this:

    <?php
    class Welcome extends CI_Controller {
        public function index() {
            $this->load->view('welcome_message');
        }
    }
    

    Then create Views and Models. Views go into application/views/ and models into application/models/. You can start adding your views and models accordingly.

    Conclusion

    Setting up a development environment for CodeIgniter on Ubuntu is an essential step to unlock the full potential of this lightweight yet powerful PHP framework.

    By carefully following the outlined steps—from installing prerequisites, configuring file permissions, and customizing settings to creating controllers, views, and models—you are now equipped to start building dynamic web applications.

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow to Use Collections in C# – Lists, Arrays, Dictionaries, and More
    Next Article How to Containerize a Node.js Application Using Docker – A Beginner’s Guide

    Related Posts

    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    June 1, 2025
    Artificial Intelligence

    LWiAI Podcast #201 – GPT 4.5, Sonnet 3.7, Grok 3, Phi 4

    June 1, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    NVIDIA fully embraces the Steam Deck with a native GeForce Now app promised for 2025

    News & Updates

    Introducing AWS MCP Servers for code assistants (Part 1)

    Machine Learning

    Three Questions I Ask Before Starting a New Design Project

    Web Development

    CVE-2025-4019 – Apache Novel-Plus Missing Authentication Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    News & Updates

    GitHub for Beginners: Building a REST API with Copilot

    April 28, 2025

    Welcome to the next episode in our GitHub for Beginners series, where we’re diving into…

    Atomfall’s Radio Towers confused the daylights out of me, but then I stumbled upon a key character and all became clear

    March 31, 2025

    Mar 21, 2025: AI updates from the past week — Anthropic web search, Gemini Canvas, new OpenAI audio models, and more

    March 21, 2025

    Development Release: Elive 3.8.48 (Beta)

    April 17, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.