agyanadda@gmail.com

CodeIgniter 4 Deployment

APIs and Advanced Topics 1 min read Updated Dec 3, 2026 Topic 29 of 30

Before uploading

  • Set CI_ENVIRONMENT = production in the server's .env
  • Set app.baseURL to your live URL with https://
  • Set the live database and email settings
  • Remove index.php from URLs: app.indexPage = '' (the .htaccess in public handles rewriting)

On a VPS (recommended)

  1. Pull the code with Git
  2. composer install --no-dev --optimize-autoloader
  3. php spark migrate
  4. Make writable writable by the web server
  5. Point the domain's document root to public
  6. Newer versions: php spark optimize caches config for speed

On shared hosting (cPanel / Hostinger)

  1. Upload the project outside public_html (for example /home/user/myapp)
  2. Copy the contents of public into public_html
  3. In public_html/index.php, fix the path to app/Config/Paths.php so it points into myapp
  4. Import the database with phpMyAdmin and set .env

After going live

Check writable/logs for errors, make sure the Debug Toolbar is not shown, and back up the database before every update.

Example

Example — VPS deployment steps Bash
cd /var/www/myapp

# 1. Get the latest code
git pull origin main

# 2. Install packages without dev tools
composer install --no-dev --optimize-autoloader

# 3. Run database migrations
php spark migrate

# 4. Clear the cache
php spark cache:clear

# 5. Permissions for the writable folder (first deploy)
sudo chown -R www-data:www-data writable
sudo chmod -R 775 writable

# Apache virtual host (document root must be public):
# DocumentRoot /var/www/myapp/public
# <Directory /var/www/myapp/public>
#     AllowOverride All
# </Directory>

After these steps the site runs the new code. AllowOverride All lets public/.htaccess remove index.php from URLs.

Test Yourself With Exercises

Exercise 1 Multiple Choice

Where should the domain's document root point?

Exercise 2 True / False

On a live site, CI_ENVIRONMENT should be development.

Exercise 3 Fill in the Blank

Install packages for production with composer install --no-___

Frequently Asked Questions

URL rewriting is not working. Make sure public/.htaccess was uploaded, mod_rewrite is on, AllowOverride All is set for Apache, and app.indexPage is '' in .env. As a quick test, try adding index.php/ in the URL.