Deployment

πŸ“˜ CodeIgniter πŸ‘ 37 views πŸ“… Dec 22, 2025
⏱ Estimated reading time: 2 min

Deployment of a CodeIgniter Application (CodeIgniter 4)

Deploying a CodeIgniter 4 app means moving it from local development to a production server safely, securely, and efficiently.


1. Server Requirements

Ensure your production server has:

  • PHP 7.4+

  • Extensions: intl, mbstring, openssl, json, mysqlnd

  • Web server: Apache or Nginx

  • Composer (recommended)

  • Database server (MySQL, PostgreSQL, etc.)


2. Project Structure for Deployment

Your server should point to the public/ directory as the web root:

/var/www/myapp/ β”œβ”€β”€ app/ β”œβ”€β”€ public/ ← document root β”œβ”€β”€ system/ β”œβ”€β”€ writable/ β”œβ”€β”€ vendor/ └── .env

βœ” This protects core files from public access


3. Upload Project Files

Options:

  • Git (git clone)

  • FTP/SFTP

  • CI/CD pipeline

Recommended:

git clone https://github.com/yourrepo/myapp.git

4. Install Dependencies

Inside the project folder:

composer install --no-dev

βœ” Excludes development packages
βœ” Optimized for production


5. Environment Configuration

Create .env file:

CI_ENVIRONMENT = production app.baseURL = 'https://example.com/' database.default.hostname = localhost database.default.database = mydb database.default.username = dbuser database.default.password = strongpassword database.default.DBDriver = MySQLi

⚠️ Never commit .env to Git


6. Set Folder Permissions

Make writable/ writable:

chmod -R 775 writable/

Owner example:

chown -R www-data:www-data writable/

7. Run Migrations (If Used)

php spark migrate

(Optional) Seed data:

php spark db:seed UserSeeder

8. Apache Configuration

Enable mod_rewrite

a2enmod rewrite

Virtual Host Example

ServerName example.com DocumentRoot /var/www/myapp/public AllowOverride All Require all granted

Restart Apache:

systemctl restart apache2

9. Nginx Configuration (Alternative)

server { server_name example.com; root /var/www/myapp/public; index index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }

10. Disable Debugging (Critical)

In production:

CI_ENVIRONMENT = production

βœ” Debug toolbar disabled
βœ” Errors hidden from users
βœ” Logs still enabled


11. Enable HTTPS

  • Use Let’s Encrypt (Certbot)

  • Force HTTPS using filter:

public $globals = [ 'before' => ['forcehttps'] ];

12. Cache & Performance Setup

  • Enable OPcache in php.ini

  • Configure CodeIgniter cache (file/Redis)

  • Enable gzip compression

  • Use CDN for assets


13. Security Checklist

βœ… .env not public
βœ… writable/ permissions correct
βœ… Errors hidden
βœ… HTTPS enabled
βœ… Database credentials secured


14. Common Deployment Issues

IssueFix
403/404 errorsWrong document root
Blank pageCheck logs in writable/logs/
CSS/JS not loadingIncorrect baseURL
Permission deniedFix writable/ permissions

15. Post-Deployment Testing

  • Test login & forms

  • Test file uploads

  • Check logs

  • Verify API endpoints

  • Load test critical pages


Summary

  • Point server to public/

  • Use production environment

  • Secure .env and permissions

  • Run migrations

  • Enable HTTPS & caching


πŸ”’ Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes