How to Deploy a Codeigniter 4 Project
require 'recipe/codeigniter4.php';
Deployer is a free and open source deployment tool written in PHP. It helps you to deploy your Codeigniter 4 application to a server. It is very easy to use and has a lot of features.
Three main features of Deployer are:
- Provisioning - provision your server for you.
- Zero downtime deployment - deploy your application without a downtime.
- Rollbacks - rollback your application to a previous version, if something goes wrong.
Additionally, Deployer has a lot of other features, like:
- Easy to use - Deployer is very easy to use. It has a simple and intuitive syntax.
- Fast - Deployer is very fast. It uses parallel connections to deploy your application.
- Secure - Deployer uses SSH to connect to your server.
- Supports all major PHP frameworks - Deployer supports all major PHP frameworks.
You can read more about Deployer in Getting Started.
The deploy task of Codeigniter 4 consists of:
- deploy:prepare – Prepares a new release
- deploy:info – Displays info about deployment
- deploy:setup – Prepares host for deploy
- deploy:lock – Locks deploy
- deploy:release – Prepares release
- deploy:update_code – Updates code
- deploy:env – Optimize environment variables
- deploy:shared – Creates symlinks for shared files and dirs
- deploy:writable – Makes writable dirs
- deploy:vendors – Installs vendors
- spark:optimize – Optimize for production.
- spark:migrate – Locates and runs all new migrations against the database.
- deploy:publish – Publishes the release
- deploy:symlink – Creates symlink to release
- deploy:unlock – Unlocks deploy
- deploy:cleanup – Cleanup old releases
- deploy:success – Deploys your project
The codeigniter4 recipe is based on the common recipe.
Configuration
public_path
Overrides public_path from recipe/provision/website.php
.
Default Configurations
'public'
shared_dirs
Overrides shared_dirs from recipe/deploy/shared.php
.
['writable']
shared_files
Overrides shared_files from recipe/deploy/shared.php
.
['.env']
writable_dirs
Overrides writable_dirs from recipe/deploy/writable.php
.
[
'writable/cache',
'writable/debugbar',
'writable/logs',
'writable/session',
'writable/uploads',
]
log_files
'writable/logs/*.log'
codeigniter4_version
$result = run('{{bin/php}} {{release_or_current_path}}/spark');
preg_match_all('/(\d+\.?)+/', $result, $matches);
return $matches[0][0] ?? 5.5;
Tasks
spark:cache:info
Shows file cache information in the current system.
Discover & Checks
spark:config:check
Check your Config values.
spark:env
Retrieves the current environment, or set a new one.
spark:filter:check
Check filters for a route.
spark:lang:find
Find and save available phrases to translate.
spark:namespaces
Verifies your namespaces are setup correctly.
spark:phpini:check
Check your php.ini values.
spark:routes
Displays all routes.
spark:key:generate
Generates a new encryption key and writes it in an .env
file.
Actions
spark:optimize
Optimize for production.
spark:publish
Discovers and executes all predefined Publisher classes.
spark:db:create
Create a new database schema.
Database and migrations.
spark:db:seed
Runs the specified seeder to populate known data into the database.
spark:db:table
Retrieves information on the selected table.
spark:migrate
Locates and runs all new migrations against the database.
spark:migrate:refresh
Does a rollback followed by a latest to refresh the current state of the database.
spark:migrate:rollback
Runs the "down" method for all migrations in the last batch.
spark:migrate:status
Displays a list of all migrations and whether they've been run or not.
spark:cache:clear
Clears the current system caches.
Housekeeping
spark:debugbar:clear
Clears all debugbar JSON files.
spark:logs:clear
Clears all log files.
spark:custom
Run a custom spark command.
Custom Spark Command for shield or setting packages
deploy
Deploys your project.
Main deploy task.
This task is group task which contains next tasks: