This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Every 1 second delay costs up to 20% conversions. Learn how to fix it [Free • Mar 10–11]. Save My Spot→

Comprehensive CodeIgniter Tutorial: Local Build to Cloud Deployment

Updated on September 26, 2025

13 Min Read
install codeigniter

Key Takeaways

  • The MVC structure is key to building scalable applications, effectively separating data (Model), logic (Controller), and interface (View).
  • Secure production deployment requires using the .env file to isolate credentials and resolving platform-specific structural issues (like the CodeIgniter /public/ folder conflict).
  • CodeIgniter is prized for its lightweight core and high speed, making it the ideal choice for rapid development and optimized applications.

CodeIgniter is an opensource MVC framework used to build dynamic PHP websites and projects such as eCommerce stores and blogs.

If you’re looking for a structured, lightweight, and high-performing tool that simplifies web development, CodeIgniter is the ideal choice. It eliminates complexity and allows you to focus on writing application logic efficiently.

In this blog, we’ll take a look at CodeIgniter Fundamentals to cover the basics: what the framework is, why its MVC architecture is essential, and its core benefits. Following the fundamentals, we’ll dive into the hands-on building process:

Part 1: Local Setup & Build: We’ll build a complete application on your local machine using XAMPP, walking through database setup and coding the MVC components.

Part 2: Cloud Deployment: Finally, we’ll cover the essential process of taking your finished PHP project live by deploying it securely to Cloudways, including database migration and final production configuration.

What is CodeIgniter?

At its heart, CodeIgniter is a powerful, open-source PHP Framework built for developers who need a simple and elegant toolkit to create dynamic web applications.

Think of it as a set of pre-built components that save you from writing the same code repeatedly. It operates using the MVC (Model-View-Controller) architectural pattern.

This structure cleanly separates the application’s business logic (Model), presentation (View), and user input handling (Controller), making your code organized, scalable, and easy to maintain.

Why Use CodeIgniter?

CodeIgniter is one of the longest-standing and most respected PHP frameworks for several compelling reasons:

  • Small Footprint, High Speed: CodeIgniter is incredibly lightweight and known for its exceptional speed and performance. It doesn’t load unnecessary libraries, keeping execution times fast.
  • Zero Configuration (Almost!): You can get a CodeIgniter project up and running with minimal setup (as we saw in our local install!), which means you can start coding your application logic faster.
  • Strong Documentation and Community: It boasts some of the clearest, most comprehensive documentation in the PHP ecosystem. If you ever get stuck, the community is always there to help.
  • Built-in Security: It comes with strong built-in security features to help you write secure applications, with tools for input validation and protection against common attacks like SQL Injection and XSS.

Part1: Build a PHP Project With CodeIgniter (Local Environment)

Imagine you’re a freelance blogger who needs a lightweight and efficient way to post articles. You don’t need a heavy CMS like WordPress; you just want something you can completely control. This is a perfect use case for CodeIgniter.

Our mini-project will have two main views:

  • A public-facing page: This will display a list of all your blog posts.
  • An admin page: A simple form where you can create a new post (title and content).

Prerequisites

Before we start, you’ll need to have a few things installed on your computer.

  • XAMPP: This is a free, all-in-one software package that gives you everything you need to run a web server on your local machine, including Apache, MariaDB (a MySQL-compatible database), and PHP. You can download it from the official Apache Friends website.
  • CodeIgniter: Download the latest stable version of CodeIgniter from its official website.
  • A code editor: I’ll be using Notepad, but you can use any editor you’re comfortable with (like Sublime Text or Atom).

Step 1: Install and Start XAMPP

First things first, let’s get our local server running.

  • Download and install XAMPP. The process is pretty straightforward—just follow the installer’s on-screen instructions.
  • Once installed, open the XAMPP Control Panel. You’ll see several modules. Click “Start” next to Apache and MySQL.

XAMPP control panel

  • You’ll know they’re running when their status turns green. This means your local web server and database are up and running!
  • To verify, open your web browser and go to http://localhost. If you see the XAMPP dashboard, you’re all set.

XAMPP dashboard

Step 2: Enable a Required PHP Extension

CodeIgniter requires the intl extension to be enabled in your PHP configuration. This extension is included with XAMPP but is not always turned on by default.

  • Go to your XAMPP folder and inside it, go to the PHP folder and open your php.ini file.
  • Inside the php.ini file, find the line ;extension=intl.
  • Remove the semicolon (;) at the beginning of the line to enable the extension. The line should now look like this: extension=intl.

php ini file

  • Save and close the php.ini file.
  • Important: You must restart Apache for the changes to take effect. Click the Stop button next to Apache and then click Start again.

Step 3: Set up the CodeIgniter Project

Now, let’s get CodeIgniter into our server’s folder.

  • Find your XAMPP installation directory. On Windows, this is usually C:\xampp.
  • Inside C:\xampp, you’ll find a folder called htdocs. This is the root directory for your web projects. All your websites will live here.
  • Extract the CodeIgniter zip file you downloaded earlier in your htdocs directory. You’ll get a folder (e.g., CodeIgniter-4.x.x). Rename this folder to something simple like my-blog. (C:\xampp\htdocs\my-blog).

CodeIgniter zip

CodeIgniter zip 1

Step 4: Configure CodeIgniter

Now we need to tell CodeIgniter about our local environment and database.

Open your my-blog folder in your code editor.

Go to app/Config/App.php.

In newer versions of CodeIgniter, the base URL is already defined for you. Find the line that says:

public string $baseURL = 'http://localhost:8080/';

Change this to include the public directory, which is the correct entry point for your application when using XAMPP. The line should be:

public string $baseURL = 'http://localhost/my-blog/public/';

This tells CodeIgniter the correct web address for your project.

While you’re here, let’s also set up cleaner URLs. Find the $indexPage line and change it to an empty string:

public string $indexPage = '';

This will remove index.php from your URLs, making them look much cleaner and more professional.

Finally, let’s set up the database connection. Go to app/Config/Database.php. In the $default array, change the values to:

  • hostname‘ should be ‘localhost‘.
  • username‘ should be ‘root‘.
  • password‘ should be (an empty string).
  • database‘ should be the name of the database we’ll create in the next step. Let’s name it ‘my_blog_db‘.

database php

Step 5: Create the Database Table

Now we need a place to store our blog posts.

  • Open your web browser and navigate to http://localhost/phpmyadmin. This is the web-based interface for managing your MySQL database.
  • On the left, click on the “New” button to create a new database.
  • Name it my_blog_db and click “Create“.

phpmyadmin

  • Now, click on the my_blog_db database you just created.

database table

  • We’re going to create a table to hold our blog posts. Let’s call it posts. Set the number of columns to 3.

table properties

  • Give it the following columns and properties:
  • id: Type INT, Length/Values 11. Check the A_I (Auto Increment) box and make it the Primary Key.
  • title: Type VARCHAR, Length/Values 255.
  • content: Type TEXT.

content text

  • Click “Save” at the bottom right. Our table is ready!

Final table

Step 6: Create the MVC Components

This is where the real CodeIgniter magic happens. We’ll create our Model, View, and Controller.

  • Create the Model: Go to the app/Models folder and create a new file named Post_model.php. Paste the following code into it:
<?php

namespace App\Models;

use CodeIgniter\Model;

class Post_model extends Model

{

protected $table = 'posts';

protected $primaryKey = 'id';

protected $allowedFields = ['title', 'content'];

public function get_posts()

{

return $this->findAll();

}

}

This model will handle all our interactions with the posts table. If you want to work with APIs or return your blog data in JSON format, you can also display data in CodeIgniter JSON using CURL for easy integration with front-end apps or external services

  • Create the Controller: Go to app/Controllers and create a new file named Blog.php. This controller will handle user requests. Paste this code:
<?php

namespace App\Controllers;

use App\Models\Post_model;

use CodeIgniter\Controller;

class Blog extends Controller

{

public function index()

{

$model = new Post_model();

$data['posts'] = $model->get_posts();

return view('blog/index', $data);

}

public function create()

{

return view('blog/create');

}

public function save()

{

$model = new Post_model();

$data = [

'title' => $this->request->getPost('title'),

'content' => $this->request->getPost('content')

];

$model->save($data);

return redirect()->to(base_url('blog'));

}

}

This controller has three main functions: index (to show all posts), create (to show the form), and save (to handle the form submission).

  • Create the Views: We need two views to display the UI.
  • Go to app/Views and create a new folder called blog.
  • Inside the blog folder, create index.php. This is the main page. Paste this HTML into it:
<!DOCTYPE html>

<html>

<head>

<title>My Awesome Blog</title>

<style>

body { font-family: Arial, sans-serif; max-width: 800px; margin: auto; padding: 20px; }

.post { border: 1px solid #ccc; padding: 15px; margin-bottom: 20px; }

.post h2 { margin-top: 0; }

a { text-decoration: none; background-color: #007bff; color: white; padding: 10px 15px; border-radius: 5px; }

</style>

</head>

<body>

<h1>My Awesome Blog</h1>

<a href="<?= base_url('blog/create') ?>">Create New Post</a>

<hr>

<?php if (!empty($posts) && is_array($posts)): ?>

<?php foreach ($posts as $post): ?>

<div class="post">

<h2><?= esc($post['title']) ?></h2>

<p><?= esc($post['content']) ?></p>

</div>

<?php endforeach; ?>

<?php else: ?>

<p>No posts found.</p>

<?php endif; ?>

</body>

</html>
  • Next, create another file inside the blog folder, named create.php. This is the post creation form.
<!DOCTYPE html>

<html>

<head>

<title>Create a New Post</title>

<style>

body { font-family: Arial, sans-serif; max-width: 600px; margin: auto; padding: 20px; }

form { display: flex; flex-direction: column; }

input, textarea { margin-bottom: 15px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; }

button { padding: 10px; background-color: #28a745; color: white; border: none; cursor: pointer; border-radius: 5px; }

a { text-decoration: none; color: #007bff; margin-top: 10px; }

</style>

</head>

<body>

<h1>Create a New Post</h1>

<form action="<?= base_url('blog/save') ?>" method="post">

<label for="title">Title:</label>

<input type="text" name="title" id="title" required>

<label for="content">Content:</label>

<textarea name="content" id="content" rows="10" required></textarea>

<button type="submit">Save Post</button>

</form>

<a href="<?= base_url('blog') ?>">Back to Posts</a>

</body>

</html>

Step 7: Define the Routes

We need to tell CodeIgniter what to do when a user visits a specific URL.

  • Open app/Config/Routes.php.
  • Find the line $routes->get(‘/’, ‘Home::index’); and comment it out or delete it.
  • Add the following lines to the file:
$routes->get('/', 'Blog::index');

$routes->get('blog', 'Blog::index');

$routes->get('blog/create', 'Blog::create');

$routes->post('blog/save', 'Blog::save');

This tells our application that when someone visits / or /blog, it should call the index method in our Blog controller. It also defines the URLs for our creation form and saving the post.

Step 8: Test Your Project

You’ve done all the hard work! Let’s see the results.

  • Open your web browser and go to your project URL: http://localhost/my-blog/public/
  • You should see a page with the title “My Awesome Blog” and a link to “Create New Post“. If you see this, it means your CodeIgniter application is running correctly.
  • Click the Create New Post button. You’ll be taken to the post creation form we built. Fill in a title and some content.
  • Click Save Post. You’ll be redirected back to the main blog page, and your new post will appear in the list!

blog page

Congratulations! You’ve successfully built a fully functional basic blog application using PHP and the CodeIgniter framework on your local machine. In our DB, we can also verify that the entries have been saved correctly.

php final database

This project is a great foundation and can be expanded with more features like editing or deleting posts.

Part 2: Deploying Our Basic Blog Application to Cloudways

We’ve successfully built and tested our application locally. Now, it’s time to put it on a live server so the whole world can see it! We’ll use Cloudways, which simplifies much of the server configuration for us.

Step 1: Set Up the Cloudways Server & Application

  • Log in to Cloudways and navigate to your main dashboard. You can click on the Servers tab or the ‘Launch Now’ button if you’re a new user. Since we need a fresh environment, I’ll click the + Add Server button.

Cloudways server

  • Select Your Application: From the list of choices, pick “Custom App“. Give your application a clear name (e.g., CodeIgniterBlog) and also name your server.

Custom app

  • Choose Your Cloud Provider: Select your preferred cloud infrastructure—I’m going with DigitalOcean, but feel free to choose from AWS, Google Cloud, or others.

providers

  • Select Server Specs: Pick the server size and location. Since our blog is just a starter project, the most basic server size and an easily accessible location will be more than enough for testing.

server specs

location

  • Launch the Server: Review the final cost estimate and click Launch Now.

launch the server

Cloudways will now handle the entire provisioning process, setting up your server and deploying your application framework. This usually takes just a few minutes.

provisioning process

Step 2: Migrate the Database (Export & Import)

We need to move the posts table from your local machine to the cloud server.

  • Export Local Database:
    • Go to your local http://localhost/phpmyadmin.
    • Select your my_blog_db.
    • Click the Export tab at the top.
    • Select SQL format. Click Export to download the my_blog_db.sql file.

export database

my db

  • Import to Cloud:

Now that we have the SQL file, let’s get our database structure and data onto the live server.

Launch the Database Manager: In your Cloudways dashboard, navigate to your new PHP application. From the Access Details screen, click the Launch Database Manager button (this is the cloud-hosted phpMyAdmin).

Launch Database Manager

Select Import: Once logged in to the manager, click the Import tab at the top.

import tab

Choose the File: Click Choose files and select the my_blog_db.sql file you exported from your local machine earlier.

select db file

Execute the Import: Finally, click the Execute button to start the process. The tool will automatically create the posts table with all the necessary columns on your live server.

execute the import

Your database is now fully migrated to the cloud and ready to connect to your CodeIgniter application. As you can see, in our table, the previous entries we made on our local setup are appearing in the DB we imported.

Step 3: Upload Project Files via SFTP (FileZilla)

Now we’ll move all the CodeIgniter files using FileZilla (or any SFTP client).

  • Connect to SFTP: Open FileZilla and use the Master Credentials from Cloudways:
    • Host: Your Public IP Address (from your server details).
    • Username: Your Master Username.
    • Password: Your Master Password.
    • Port: 22 (default for SFTP).

connect to SFTP

  • Navigate to Destination: In the remote site pane (Cloudways), navigate to: applications/your_app_name/public_html/.

Navigate to Destination

  • Zip the Project Locally: On your local machine, zip the entire my-blog project folder (which contains the app, system, public, vendor, etc. directories) into a single file, like my-blog.zip.

Zip the Project Locally

  • Transfer the Zip: Use FileZilla to upload only the my-blog.zip file to the remote public_html directory.

Transfer the Zip

  • Unzip via SSH: This is the crucial step. FileZilla itself cannot unzip files on the server. You’ll need to use the Cloudways SSH Terminal (which you can access directly from your server tab) to execute a simple command:

Unzip via SSH

unzip "YOUR_PROJECT_NAME.zip"
  • You must first navigate to the correct directory (applications/your_app_name/public_html) before running the command. In my case it is: cd applications/ybvtcddqwu/public_html.

directory

  • Clean Up: Once the unzipping is complete, you can safely delete the zip file and the original my-blog.zip file using SSH to keep your server clean:
rm "YOUR_PROJECT_NAME.zip"

Lastly, We need to run two quick commands via SSH to move the files into the main public_html root directory and then remove the now-empty subfolder.

mv YOUR_EXTRACTED_FOLDER_NAME/* .

rmdir YOUR_EXTRACTED_FOLDER_NAME

Now all of our project files are in the public_html directory of our application.

public_html

Step 4: Update the Configuration (The .env File)

The most important step is configuring the application to work in the new cloud environment. We’ll use the environment file, which is best practice for production settings.

  • Rename the Environment File: In the public_html folder on your server (via SFTP), find the file named env.
  • Rename this file to .env (make sure you include the dot at the beginning).

Rename the Environment File

Edit the .env File: Open the newly renamed .env file and make the following changes. You’ll need to uncomment these lines (remove the #) and replace the placeholders with your Cloudways details:

CI_ENVIRONMENT = production
  • App URL (Base URL): Set the URL to your live domain, making sure to include /public/ at the end as this is the application’s entry point.

app.baseURL = ‘http://YOUR_APP_URL.cloudwaysapps.com/public/

  • Database Credentials: Update these lines with the Cloudways DB Name, Username, and Password. You can find the Access Details tab of your application. These settings will override the local ones we put in Database.php.

Database Credentials

database.default.hostname = localhost # <-- UNCOMMENT AND SET THIS LINE!

database.default.database = 'YOUR_CLOUD_DB_NAME'

database.default.username = 'YOUR_CLOUD_DB_USERNAME'

database.default.password = 'YOUR_CLOUD_DB_PASSWORD'

Save the file. Your CodeIgniter application is now securely configured for the cloud!

Step 5: Final Test and Deployment Complete!

Now your entire application is deployed and configured.

  • You should see your live blog. Click the Create New Post button to verify that the routing and the database connection are working correctly on the cloud server.

blog deployed

And that is it, your basic blog application is now successfully deployed and running on Cloudways.

Conclusion

Congratulations! You successfully completed the entire lifecycle of a modern web application. You built a full CodeIgniter MVC application locally and flawlessly deployed it to a production environment on Cloudways, conquering complex issues like file permissions and base URL conflicts along the way.

You now have a robust foundation. Your next step should be to expand on this success:

  • Complete CRUD: Add the Update and Delete functionalities to your application.
  • Security & Features: Implement user logins and advanced form validation.

If you have any questions, let me know in the comments below.

Q. Why is CodeIgniter not popular?

CodeIgniter’s popularity declined primarily due to a period of stagnation (around 2015-2019) when development slowed down. While CI4 is modern, many developers switched to Laravel because it offers a richer, built-in ecosystem (like ORMs and authentication) that CI lacks out-of-the-box. CI remains popular for speed-focused projects.

Q. Which is better, Laravel or CodeIgniter?

Neither is universally better; it depends on the project scope. CodeIgniter is better for lightweight apps, rapid prototyping, and shared hosting because it’s faster and simpler to learn. Laravel is better for large, complex applications that require advanced, built-in enterprise features and extensive tools.

Q. How to set up CodeIgniter in localhost?

You set it up by installing XAMPP (for Apache, PHP, and MySQL) and extracting the CodeIgniter files into the htdocs folder. Then, you enable the intl extension in php.ini and configure the application’s base URL to point to the secure /public/ subdirectory.

Q. How to install CodeIgniter in cPanel?

Install CodeIgniter by uploading the project ZIP to public_html via File Manager and extracting it. You must then use cPanel to create a database and edit the project’s .env file with the new credentials. Finally, ensure the domain’s web root points to the public subdirectory for security.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdul Rehman

Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour