Skip to content

CodeIgniter 4.4.5+ template with docker configuration for development & production

License

Notifications You must be signed in to change notification settings

trubusoft/codeigniter4-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeIgniter 4 Starter Template

Status Badge Coverage Badge

Starter template for CodeIgniter 4.4.5+ with:

  • Docker configuration for both development & production.
  • Test & Coverage workflow template with GitHub runner

Tested for development & production on Ubuntu 20.04 LTS.

Folder Structure

  • configurations: various development/deployment configurations (e.g. docker/kubernetes config for dev, staging, and production)
  • documents: all files that not directly related to the code and will not be included inside source image (e.g. requirements, notes, diagram)
  • source: root folder for the CI4 project

Installation

Installing PHP

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3
php -v

Installing Required PHP Module for CI4

  • mysql: for connecting with MySQL
  • curl: for composer
  • intl: for CI4
  • dom: for PHPUnit
  • mbstring: for PHPUnit
  • xdebug: code coverage driver for PHPUnit
sudo apt install php8.3-mysql
sudo apt install php8.3-curl
sudo apt install php8.3-intl
sudo apt install php8.3-dom
sudo apt install php8.3-mbstring
sudo apt install php8.3-xdebug

Check that above modules exist by running php -m.

Optional PHP Modules

Should only be installed if required, or any error occurred that mentions them.

  • sqlite3: for CI4 default testing with sqlite3 database
sudo apt install php8.3-sqlite3

Installing Composer

Refer to: https://getcomposer.org/download/

Installing Dependencies

cd source
composer install

Running the starter template

Try running the bare minimum settings now with:

cd source
php spark serve

A page should now be served at http://localhost:8080/.

If you can see the page, then CodeIgniter 4 related modules & packages have been installed successfully.

Development Configuration

Environment setting

  • Copy & rename env.dev to .env.
  • Modify as needed
  • Confirm the currently active environment with ./spark env. It should now show development instead of production.

Spin up MySQL Database

The provided docker-compose.yml will spin up 2 database (main and test).

docker compose up -d

Run the development session

You can start the development session with the built-in spark:

cd source
php spark serve

The bitnami/codeigniter image can also be used instead as an alternative to the spark. For this, please refer to development_with_bitnami_image.md.

Testing

Run the tests with:

cd source
composer test

or generate coverage report with:

cd source
composer coverage

Coverage report will be created at /source/build/logs.

Debugging

  • Use the provided Debug Toolbar
  • Error logs will be printed on writable/logs

Production Configuration

This repo offers a working configuration for serving the source code on a production environment with PHP-FPM and NGINX. More about this can be found at production.md.

Useful external resources