Introduction
Are you ready to graduate from shared hosting?
If you are running a CodeIgniter 4 (CI4) application on cPanel, you might feel a bit constrained. Maybe your site is growing, or maybe you just want the raw power and flexibility of the cloud. Whatever the reason, moving to Amazon Web Services (AWS) is a massive upgrade for your career and your website.
But let’s be honest—staring at a black terminal screen instead of the friendly cPanel interface can be scary. 😨
Don’t worry! I’m going to walk you through this process just like I’m sitting right next to you. We aren’t just moving files; we are setting up a professional production environment. By the end of this guide, you will have your CI4 site running on an AWS EC2 Ubuntu server with a custom domain and a secure green padlock (SSL).
Let’s dive in! 🚀
📋Table of Contents
1. The Exit: Backing up from cPanel
Before we touch AWS, we need to pack our bags. We need two things: your files and your database.
Step A: Backup Your Files
- Log in to your cPanel.
- Open File Manager.
- Navigate to your project folder (usually inside
public_html). - Select all files (ensure you include hidden files like
.envand.gitignore). - Right-click and select Compress (Zip Archive).
- Name it
ci4_backup.zipand download it to your computer.
Step B: Backup Your Database
- Open phpMyAdmin in cPanel.
- Click on your database name in the left sidebar.
- Click the Export tab at the top.
- Keep the settings as default (SQL format) and click Go.
- Save the
.sqlfile (e.g.,db_backup.sql).
2. The Destination: Setting up AWS EC2
Now, let’s build your new home in the cloud.
- Log in to the AWS Console.
- Search for EC2 and click Launch Instance.
- Name:
CI4-Web-Server - OS Image: Choose Ubuntu Server 24.04 LTS (or 22.04).
- Instance Type:
t2.micro(This is free-tier eligible! 💸). - Key Pair: Create a new key pair (e.g.,
myserver-key.pem). Download this and keep it safe! - Network Settings: Check the boxes to allow traffic from:
- SSH (Port 22)
- HTTP (Port 80)
- HTTPS (Port 443)
- Click Launch Instance.
Wait a minute for the instance to start, then copy its Public IPv4 address.
3. The Move: Connecting & Installing Software (AWS EC2)
Open your terminal (Mac/Linux) or PowerShell/Git Bash (Windows). Navigate to where you saved your key file (myserver-key.pem).
Connect to the Server
Bash
# Fix key permissions (Mac/Linux only)
chmod 400 myserver-key.pem
# Connect
ssh -i "myserver-key.pem" ubuntu@YOUR_AWS_IP_ADDRESS
Install the Tech Stack (LAMP)
CodeIgniter 4 needs specific PHP extensions to run smoothy. Run these commands one by one:
Bash
# 1. Update the server
sudo apt update && sudo apt upgrade -y
# 2. Install Apache Web Server
sudo apt install apache2 -y
# 3. Install MySQL Database
sudo apt install mysql-server -y
# 4. Install PHP 8.1 (or 8.2/8.3) and required extensions for CI4
sudo apt install php libapache2-mod-php php-mysql php-intl php-curl php-gd php-xml php-mbstring php-zip -y
# 5. Restart Apache to apply changes
sudo systemctl restart apache2
4. The Transfer: Moving Your Files (AWS EC2)
Now we need to get your ci4_backup.zip and db_backup.sql from your computer to the AWS server. We will use a secure copy command (scp).
Open a NEW terminal window on your computer (don’t close the server connection) and run:
Bash
# Upload Zip file
scp -i "myserver-key.pem" path/to/ci4_backup.zip ubuntu@YOUR_AWS_IP_ADDRESS:/home/ubuntu/
# Upload SQL file
scp -i "myserver-key.pem" path/to/db_backup.sql ubuntu@YOUR_AWS_IP_ADDRESS:/home/ubuntu/
Unzip and Place Files
Go back to your Server Terminal window.
Bash
# Go to web root
cd /var/www/html/
# Remove default index.html
sudo rm index.html
# Move the zip file here
sudo mv /home/ubuntu/ci4_backup.zip .
# Unzip it (install unzip if needed: sudo apt install unzip)
sudo unzip ci4_backup.zip
# Clean up
sudo rm ci4_backup.zip
5. The Brain: Database & CI4 Configuration (AWS EC2)
This is the part where most beginners get stuck. Let’s make sure you don’t!
Import the Database
Bash
# Login to MySQL
sudo mysql
# Run these SQL commands (Replace 'strong_password' with a real one!)
CREATE DATABASE my_project_db;
CREATE USER 'ci4_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON my_project_db.* TO 'ci4_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Now, import your data:
Bash
# Import the SQL file we uploaded earlier
sudo mysql -u ci4_user -p my_project_db < /home/ubuntu/db_backup.sql
Configure CodeIgniter (.env)
Edit your environment file:
Bash
sudo nano /var/www/html/.env
Update these lines to match your new AWS setup:
Ini, TOML
CI_ENVIRONMENT = production
app.baseURL = 'https://your-domain.com/'
database.default.hostname = localhost
database.default.database = my_project_db
database.default.username = ci4_user
database.default.password = StrongPassword123!
database.default.DBDriver = MySQLi
Press CTRL+X, then Y, then Enter to save.
⚠️ Critical Step: Folder Permissions
CodeIgniter needs to write logs and cache files. If you skip this, you will get errors!
Bash
# Give ownership to Apache
sudo chown -R www-data:www-data /var/www/html/
# correct permissions for the writable folder
sudo chmod -R 775 /var/www/html/writable/
6. The Config: Apache Virtual Host (AWS EC2)
CodeIgniter 4 is designed so that only the public folder is exposed to the internet. We need to tell Apache this.
Bash
sudo nano /etc/apache2/sites-available/ci4.conf
Paste this configuration inside:
Apache
<VirtualHost *:80>
ServerAdmin admin@your-domain.com
ServerName your-domain.com
ServerAlias www.your-domain.com
# Point directly to the PUBLIC folder
DocumentRoot /var/www/html/public
<Directory /var/www/html/public>
Options Indexes FollowSymLinks
# AllowOverride All is crucial for .htaccess to work!
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the site and the rewrite module (for pretty URLs):
Bash
sudo a2dissite 000-default.conf
sudo a2ensite ci4.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
7. The Address: DNS Setup (AWS EC2)
Now, let’s point your domain name (e.g., example.com) to your AWS server.
- Log in to your Domain Registrar (GoDaddy, Namecheap, BigRock, etc.).
- Go to DNS Management.
- Add/Edit the A Record:
- Host/Name:
@ - Value/Points to: Your AWS Public IP Address (e.g.,
54.123.45.67) - TTL: Automatic or 1 Hour.
- Host/Name:
- Add a CNAME Record:
- Host:
www - Value:
example.com
- Host:
Note: DNS propagation can take anywhere from 10 minutes to 24 hours.
8. The Lock: SSL Setup (HTTPS)
Security is not optional in 2025. You have two choices here.
Option A: The Free Route (Let’s Encrypt) 🟢
This is the best option for most blogs and standard sites. It renews automatically.
Bash
# Install Certbot
sudo apt install certbot python3-certbot-apache -y
# Request the certificate
sudo certbot --apache
Follow the prompts (enter email, agree to terms). Select “Redirect HTTP to HTTPS” when asked. Boom! You are secure.
Option B: The Paid Route (Comodo / Sectigo / DigiCert) 🟡
If you are an E-commerce site or need “Organization Validation” (OV), you might have bought a certificate.
- Generate CSR on AWS:Bash
openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr - Copy the content of
.csrand paste it into your SSL provider’s dashboard. - Download the
.crtandca-bundlefiles they give you. - Upload them to
/etc/ssl/on your server. - Edit your Apache config (
ci4.conf) to include:
Apache
<VirtualHost *:443>
ServerName your-domain.com
DocumentRoot /var/www/html/public
SSLEngine on
SSLCertificateFile /etc/ssl/yourdomain.crt
SSLCertificateKeyFile /etc/ssl/yourdomain.key
SSLCertificateChainFile /etc/ssl/ca-bundle.crt
</VirtualHost>
🎉 Conclusion (AWS EC2)
You did it! 👏
You have successfully migrated your CodeIgniter 4 application from a shared cPanel hosting to a powerful AWS EC2 server. You’ve configured the database, secured the file permissions, pointed your domain, and locked it down with SSL.
Quick Recap of what you achieved:
- ✅ Created a full VPS environment on Ubuntu.
- ✅ Configured Apache specifically for CI4 security.
- ✅ Automated SSL renewals.
Your site is now ready to handle more traffic and scale as your business grows.
💬Did you find this migration guide helpful?
I’d love to hear how your migration went! Did you run into any specific errors? Drop a comment below or share this guide with a developer friend who is still stuck on shared hosting! 👇
For more tutorials on CodeIgniter and AWS, check out our Web Development Services Blog.
