Skip to content

Setup CodeIgniter

Setup CodeIgniter

This example installs a legacy CodeIgniter 3 application inside Devilbox. For new projects, prefer Setup CodeIgniter4 because CodeIgniter 4 is the actively maintained line.

Overview

Project nameContainer pathDatabaseTLD_SUFFIXProject URL
my-ci/shared/httpd/my-cimy_cilvh.mehttp://my-ci.lvh.me / https://my-ci.lvh.me

Inside the PHP container, projects are available in /shared/httpd/; on the host they are stored below ./data/www/.

Prerequisites

  • Devilbox installed with PHP, HTTPD, MySQL, and Bind available.
  • Docker Compose v2 and the ./dvl.sh CLI.
  • TLD_SUFFIX=lvh.me or an equivalent local DNS setup.

Start the required services:

Terminal window
./dvl.sh up php httpd mysql bind

Walk through

It will be ready in eight steps:

  1. Enter the PHP container.
  2. Create a new virtual host directory.
  3. Download CodeIgniter 3.
  4. Link the document root.
  5. Add a MySQL database.
  6. Configure the database connection.
  7. Verify DNS.
  8. Open the project in a browser.

1. Enter the PHP container

Terminal window
./dvl.sh shell php83

2. Create the vhost directory

Terminal window
mkdir -p /shared/httpd/my-ci
cd /shared/httpd/my-ci

3. Download CodeIgniter

Terminal window
wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.13.tar.gz
tar xfz 3.1.13.tar.gz

Expected structure:

Terminal window
tree -L 1
.
├── 3.1.13.tar.gz
└── CodeIgniter-3.1.13

CodeIgniter 3 keeps index.php in the project root, so link the extracted directory to htdocs:

Terminal window
ln -s CodeIgniter-3.1.13 htdocs

5. Add the MySQL database

Terminal window
mysql -u root -h 127.0.0.1 -p -e 'CREATE DATABASE my_ci CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'

6. Configure the database connection

Edit htdocs/application/config/database.php:

$db['default'] = array(
'hostname' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database' => 'my_ci',
'dbdriver' => 'mysqli',
'char_set' => 'utf8mb4',
'dbcollat' => 'utf8mb4_unicode_ci',
);

Use your configured MySQL password when one is set in .env.

7. Verify DNS

my-ci.lvh.me resolves to 127.0.0.1 by default. For a custom suffix, add a hosts entry:

Terminal window
127.0.0.1 my-ci.example

8. Open your browser

Visit http://my-ci.lvh.me or https://my-ci.lvh.me.

Next steps

  • Move new projects to CodeIgniter 4 where possible.
  • Use Devilbox intranet database tools for inspection.
  • Configure HTTPS and Xdebug after the application loads.