Deploy website ke VPS itu skill wajib untuk web developer. Pertama kali saya coba, prosesnya membingungkan — banyak langkah yang harus urut. Di sini saya tulis step-by-step yang sudah saya coba sendiri, dari beli VPS sampai website online dengan HTTPS.
VPS (Virtual Private Server) adalah server virtual yang berjalan di dalam server fisik. Berbeda dengan shared hosting, kamu mendapatkan resource dedicated (CPU, RAM, storage) dan akses root penuh. VPS memberikan fleksibilitas untuk install software apapun dan konfigurasi server sesuai kebutuhan.
Setelah membeli VPS, kamu akan mendapatkan IP address, username (root), dan password. Koneksi ke VPS menggunakan SSH:
# Koneksi ke VPS
ssh root@YOUR_VPS_IP
# Contoh
ssh [email protected]
# Setelah pertama kali login, buat user baru (jangan pakai root untuk sehari-hari)
adduser deploy
usermod -aG sudo deploy
# Setup SSH key (lebih aman dari password)
# Di local machine, generate SSH key:
ssh-keygen -t ed25519 -C "[email protected]"
# Copy public key ke VPS
ssh-copy-id deploy@YOUR_VPS_IP
# Update system
sudo apt update && sudo apt upgrade -y
# Setup firewall (UFW)
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable
# Cek status firewall
sudo ufw status
# Install fail2ban (proteksi dari brute force)
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
# Install Nginx
sudo apt install nginx -y
# Start dan enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
# Cek status
sudo systemctl status nginx
# Test: buka http://YOUR_VPS_IP di browser
# Jika muncul "Welcome to nginx!" = berhasil
# Install PHP 8.2 dan extensions yang dibutuhkan
sudo apt install php8.2-fpm php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-bcmath php8.2-intl php8.2-readline php8.2-opcache -y
# Cek versi PHP
php -v
# Cek PHP-FPM status
sudo systemctl status php8.2-fpm
# Install MySQL
sudo apt install mysql-server -y
# Secure installation
sudo mysql_secure_installation
# Jawab pertanyaan:
# - Set root password? Y (masukkan password kuat)
# - Remove anonymous users? Y
# - Disallow root login remotely? Y
# - Remove test database? Y
# - Reload privilege tables? Y
# Login ke MySQL dan buat database
sudo mysql -u root -p
# Di dalam MySQL shell:
CREATE DATABASE mywebsite;
CREATE USER 'webuser'@'localhost' IDENTIFIED BY 'PasswordKuat123!';
GRANT ALL PRIVILEGES ON mywebsite.* TO 'webuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
# Di LOCAL machine, upload website files ke VPS
# Cara 1: Menggunakan scp
scp -r /path/to/your/website/* deploy@YOUR_VPS_IP:/var/www/mywebsite/
# Cara 2: Menggunakan rsync (lebih cepat, bisa resume)
rsync -avz -e ssh /path/to/your/website/ deploy@YOUR_VPS_IP:/var/www/mywebsite/
# Cara 3: Menggunakan Git (recommended untuk development)
cd /var/www/mywebsite
sudo git clone https://github.com/username/repo.git .
# Set permissions yang benar
sudo chown -R www-data:www-data /var/www/mywebsite
sudo chmod -R 755 /var/www/mywebsite
sudo chmod -R 775 /var/www/mywebsite/writable # untuk CI4
# Buat file konfigurasi Nginx
sudo nano /etc/nginx/sites-available/mywebsite
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/mywebsite/public;
index index.php index.html;
# Logging
access_log /var/log/nginx/mywebsite-access.log;
error_log /var/log/nginx/mywebsite-error.log;
# Handle CodeIgniter 4 routing
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# PHP-FPM
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
}
# Deny access to hidden files
location ~ /\. {
deny all;
}
# Cache static files
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|webp|woff|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}
# Enable site
sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
# Remove default site (opsional)
sudo rm /etc/nginx/sites-enabled/default
# Test konfigurasi
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginx
# Di dashboard domain registrar (Namecheap, Cloudflare, dll):
# Tambahkan DNS records:
# Type: A | Name: @ | Value: YOUR_VPS_IP
# Type: A | Name: www | Value: YOUR_VPS_IP
# Tunggu propagasi DNS (biasanya 5-30 menit)
# Cek dengan:
dig yourdomain.com
# Atau
nslookup yourdomain.com
# Install Certbot
sudo apt install certbot python3-certbot-nginx -y
# Generate dan install SSL certificate
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Ikuti instruksi:
# - Masukkan email
# - Agree to terms: Y
# - Redirect HTTP to HTTPS: 2 (Yes)
# Cek auto-renewal
sudo certbot renew --dry-run
# SSL akan otomatis diperbarui setiap 90 hari
# Untuk CodeIgniter 4, jalankan migration
cd /var/www/mywebsite
php spark migrate
# Set environment ke production
# Edit .env file
nano .env
# Ubah: CI_ENVIRONMENT = production
# Test website di browser
# https://yourdomain.com
# Monitor log jika ada error
sudo tail -f /var/log/nginx/mywebsite-error.log
sudo systemctl status php8.2-fpmpublicls -la /var/www/mywebsitesudo tail -f /var/log/nginx/mywebsite-error.log.env atau config databaseDeploy website ke VPS memang butuh beberapa langkah, tapi setelah dipahami, prosesnya menjadi rutin. Keuntungan VPS: kontrol penuh, performa lebih baik, dan biaya lebih murah dibanding managed hosting untuk traffic tinggi. Setelah deploy pertama berhasil, update website selanjutnya cukup upload file baru dan restart PHP-FPM. Untuk workflow yang lebih profesional, pelajari CI/CD dengan GitHub Actions atau GitLab CI untuk auto-deploy setiap push ke repository.