Docksal Setup

Thoughts on running CodeIgniter with Docksal.

Initial setup is easy

# Setup CodeIgniter
composer create-project codeigniter4/appstarter myproject 
cd myproject

# Initialise a new Docksal project
# set DOCROOT to public
fin init

# Plug the database settings into the project
echo "
database.default.hostname = getenv('MYSQL_HOST')
database.default.database = getenv('MYSQL_DB')
database.default.username = getenv('MYSQL_USER')
database.default.password = getenv('MYSQL_PASSWORD')
" >> .env

# Done
fin project start

Don't remember there being more to it. 

Stack assumptions

fin init starts a LAMP stack. CodeIgniter project requires changing database settings in .env.
However it turns out this is managed by CI, so the settings in the file are picked up without having to make changes!

Missing spark add-on

Like Laravel's artisan, CodeIgniter has a helper utility called spark. There is no add-on, but it's easy to make.
Currently this means you type commands a bit more verbosely, for example fin exec php spark whatevs.

Run the spark dev server

I'm not sure if this is needed really (as discussed under Stack assumptions), however if you have a need (let me know), then the dev server can be exposed as follows:

Create .docksal/docksal-local.yml with the following contents:

version: "2.1"

services:
  cli:
    ports:
      - '8080:8080'

Apply using fin start. Run using fin exec php spark serve -host 0.0.0.0 then open https://myproject.docksal.site:8080.