Web System Technologies
IT0049
Module 2
CodeIgniter Installation
and Configuration
Objectives
• To introduce CodeIgniter as an MVC framework.
• To familiarize student on CodeIgniter’s features,
application flow chart, concepts, design and
architectural goals.
• To learn how to install CodeIgniter 4
• To be able to configure the environment settings
• To explore the directory structure
CodeIgniter
CodeIgniter is an open-source web framework, for creating
web sites with PHP and is loosely based on model–view–
controller (MVC) development pattern.
CodeIgniter can be also modified to use Hierarchical Model
View Controller (HMVC).
CodeIgniter at a Glance
• Is an Application Framework
• Free
• Light weight
• Fast
• Uses M-V-C
• Generates clean URLs
• Extensible
• Does Not Require a Template Engine
• Thoroughly Documented
CodeIgniter MVC
MVC is a software approach that separates application logic
from presentation. In practice, it permits your web pages to
contain minimal scripting since the presentation is separate
from the PHP scripting.
• The Model represents your data structures.
• The View is the information that is being presented to a
user.
• The Controller is the intermediary between the Model, the
View, and any other resources.
CodeIgniter Features
• Model-View-Controller Based System
• Extremely Light Weight
• Full Featured database classes with support for several
platforms.
• Query Builder Database Support
• Form and Data Validation
• Security and XSS Filtering
• Session Management
CodeIgniter Features
• Email Sending Class.
• Image Manipulation Library
• File Uploading Class
• FTP Class
• Localization
• Pagination
CodeIgniter Features
• Data Encryption
• Benchmarking
• Full Page Caching
• Error Logging
• Application Profiling
• Calendaring Class
• User Agent Class
• Zip Encoding Class
CodeIgniter Features
• Template Engine Class
• Trackback Class
• XML-RPC Library
• Unit Testing Class
• Search-engine Friendly URLs
• Flexible URI Routing
• Support for Hooks and Class Extensions
• Large library of “helper” functions
Design and Architectural
Goals
CodeIgniter’s goal is to obtain maximum performance,
capability, and flexibility.
CodeIgniter was created with the following objectives:
• Dynamic Instantiation
• Loose Coupling
• Component Singularity
Software Requirements
• OS (Cross Platform)
• Web Browser
• Web Server (Apache)
• Text Editor
CodeIgniter Setup
PHP Version Requirement
PHP Version 7.3 or Higher: CodeIgniter 4 requires at least
PHP 7.3. This version introduces several new features and
optimizations that CodeIgniter 4 relies on, including improved
performance and security enhancements.
Installation
CodeIgniter has two supported installation methods: manual
download, or using Composer.
•CodeIgniter recommends the Composer installation because
it keeps CodeIgniter up to date easily.
•If you would like the simple “download & go” install that
CodeIgniter 3 is known for, choose the manual installation.
Composer Installation
In the folder above your project root run:
composer create-project codeigniter4/appstarter project-
root
The command above will create a project-root folder.
If you omit the “project-root” argument, the command will
create an “appstarter” folder, which can be renamed as
appropriate.
Manual Installation
1. Visit the CodeIgniter 4
official website or the
GitHub repository.
2. Navigate to the
“Downloads” section.
3. Download the latest
stable release as a ZIP
file.
Manual Installation
After downloading the ZIP file, it needs to be extracted to your web
server’s root directory.
1. Locate the downloaded ZIP file on your system.
2. Right-click on the ZIP file and select “Extract All…” or use a file extraction
tool like WinRAR, 7-Zip, or macOS built-in utility.
3. Extract the contents to a directory within your web server’s document
root (e.g., htdocs for XAMPP or www for WAMP).
Initial Configurations
Configuring the environment:
CodeIgniter 4 requires some initial
configuration to work correctly.
1. Rename the env file (located in the
root directory) to .env. This file
contains environment-specific
settings.
2. Open the .env file in a text editor.
3. Set the CI_ENVIRONMENT
variable to development or
production, depending on your
needs.
Initial Configurations
Setting up the BASE URL:
The base URL configuration tells CodeIgniter where the application is located.
1. Open app/Config/[Link] in a text editor.
2. Locate the $baseURL variable and set it to the URL where your application will be accessed.
If you need more flexibility, the baseURL may be set within the .env file as [Link] = '[Link]
Always use a trailing slash on your base URL!
Initial Configurations
Setting up the Index Page:
If you don’t want to include [Link] in your site URIs,
set $indexPage to ''. The setting will be used when the
framework generates your site URIs.
Verifying Installation
After setting up, verify that
CodeIgniter 4 is installed correctly.
[Link] a web browser and navigate to
[Link]
(replace your-project-folder with the
actual folder name).
[Link] should see the default CodeIgniter
welcome page if the installation is
successful.
Exploring the Directory
Structure
1. Root Directory
2. Application Directory
3. System Directory
4. Public Directory
Root Directory
The root directory contains the main files and folders of the
CodeIgniter 4 application.
• [Link]: The entry point for the application. initializes the framework and
loads the appropriate components based on the request.
• env: Environment file (usually renamed to .env), which contains environment-
specific settings.
• [Link]: Composer configuration file that manages dependencies.
• Application (app) directory: Contains the application’s code, including
controllers, models, views, and configuration files.
• Public directory: Where publicly accessible files are stored. It serves as the
entry point for web requests.
• System directory: Contains the core framework files of CodeIgniter 4.
• Tests directory: This directory is set up to hold your test files.
• Writable directory: Stores cache files, logs, and any uploads user might send.
Application (app) Directory
The app directory is where all of your application code lives. This comes with a
default directory structure that works well for many applications.
The following folders make up the basic contents:
app/
Config/ Stores the configuration files
Controllers/ Controllers determine the program flow
Database/ Stores the database migrations and seeds files
Filters/ Stores filter classes that can run before and after controller
Helpers/ Helpers store collections of standalone functions
Language/ Multiple language support reads the language strings from here
Libraries/ Useful classes that don't fit in another category
Models/ Models work with the database to represent the business entities
ThirdParty/ ThirdParty libraries that can be used in application
Views/ Views make up the HTML that is displayed to the client
System Directory
This directory stores the files that make up the framework, itself.
While you have a lot of flexibility in how you use the application
directory, the files in the system directory should never be
modified. Instead, you should extend the classes, or create new
classes, to provide the desired functionality.
All files in this directory live under the CodeIgniter namespace.
Public Directory
The public folder holds the browser-accessible portion of
your web application, preventing direct access to your source
code.
It contains the main .htaccess file, [Link], and any
application assets that you add, like CSS, javascript, or
images.
This folder is meant to be the “web root” of your site, and
your web server would be configured to point to it.
Common Config Options
• Base URL: app/Config/[Link]
• Database Settings: app/Config/[Link]
• Error Handling: app/Config/[Link]
• Session Management: app/Config/[Link]
CodeIgniter URLs
Overview
By default, URLs in CodeIgniter are designed to be search-
engine and human-friendly. Rather than using the standard
“query-string” approach to URLs that is synonymous with
dynamic systems, CodeIgniter uses a segment-based approach:
[Link]
URL Structure
Base URL contains only the Hostname:
When you have the Base URL [Link] and imagine the following URL:
[Link]
Term Example Description
Base URL is often denoted as
Base URL [Link]
baseURL.
URI path /blog/news/2022/10
The URI path relative to the Base
Route path /blog/news/2022/10
URL. It is also called as URI string.
Query page=2
URL Structure
Base URL contains sub folders:
When you have the Base URL [Link] and imagine the
following URL:
[Link]
Term Example Description
Base URL is often denoted as
Base URL [Link]
baseURL.
URI path /ci-blog/blog/news/2022/10
The URI path relative to the Base
Route path /blog/news/2022/10
URL. It is also called as URI string.
Query page=2
URI SECURITY
CodeIgniter is fairly restrictive regarding which characters it allows in your
URI strings (Route path) in order to help minimize the possibility that
malicious data can be passed to your application. URIs may only contain the
following:
• Alpha-numeric text (latin characters only)
• Tilde: ~
• Percent sign: %
• Period: .
• Colon: :
• Underscore: _
• Dash: -
• Space: `` ``
Removing the [Link] file
When you use Apache Web Server, by default, the [Link] file will be needed in your URLs:
[Link]/[Link]/news/article/my_article
If your server supports rewriting URLs you can easily remove this file with URL rewriting. This is
handled differently by different servers, but we will show examples for the two most common web
servers here.
Apache Web Server
Apache must have the mod_rewrite extension enabled. If it does, you can use a .htaccess file with
some simple rules. Here is an example of such a file, using the “negative” method in which everything
is redirected except the specified items:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ [Link]/$1 [L]