Menyiapkan lingkungan produksi di Ubuntu Server
Jump to navigation
Jump to search
Tujuan Pembelajaran:
Setelah mengikuti modul ini, mahasiswa akan mampu:
- Menyiapkan server Ubuntu untuk produksi
- Menginstal software pendukung seperti Nginx, Node.js, PHP, dan MySQL
- Men-deploy aplikasi web ke server
- Mengatur domain dan HTTPS dengan Let's Encrypt
1. Persiapan Server
Spesifikasi Minimum:
- Ubuntu Server 24.04 LTS
- Akses root (SSH atau langsung)
2. Update dan Keamanan Dasar
Update Sistem
sudo apt update && sudo apt upgrade -y
Buat User Baru (opsional)
adduser webuser usermod -aG sudo webuser
Setup Firewall (UFW)
sudo apt install ufw -y sudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' sudo ufw enable
3. Instalasi Nginx (Web Server)
sudo apt install nginx -y sudo systemctl enable nginx sudo systemctl start nginx
> Tes di browser: Akses IP server, pastikan halaman “Welcome to Nginx” muncul.
4. Menyiapkan Aplikasi Web
Opsi 1: Node.js (React, Express)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs node -v
Opsi 2: PHP + MySQL (Laravel)
sudo apt install php php-cli php-mysql php-curl php-mbstring php-xml php-zip unzip mysql-server -y
5. Deploy Aplikasi ke Server
Misalnya aplikasi React/Node.js:
# Masuk ke direktori web cd /var/www/myapp # Clone proyek (misalnya dari GitHub) git clone https://github.com/username/myapp.git # Install dependency cd myapp npm install npm run build # untuk React
6. Jalankan Aplikasi di Latar Belakang
Gunakan PM2 untuk Node.js
sudo npm install -g pm2 pm2 start npm --name "myapp" -- start pm2 startup pm2 save
7. Konfigurasi Nginx sebagai Reverse Proxy
Buat file konfigurasi Nginx:
sudo nano /etc/nginx/sites-available/myapp
Isi contoh (untuk Node.js):
server { listen 80; server_name yourdomain.com; location / { proxy_pass http://localhost:3000; # Port dari Node.js proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
Aktifkan config:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
8. Menambahkan SSL dengan Let's Encrypt
Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Jalankan Sertifikat Otomatis:
sudo certbot --nginx -d yourdomain.com
Tes SSL renewal otomatis:
sudo certbot renew --dry-run
9. Struktur Direktori yang Direkomendasikan
/var/www/ ├── myapp/ │ ├── build/ # Hasil build frontend │ ├── server/ # File backend (Node.js) │ ├── .env # Konfigurasi environment
10. Tugas Praktik Mahasiswa
Tujuan:
Mahasiswa meng-host aplikasi web sederhana ke Ubuntu Server
Instruksi:
- Siapkan server Ubuntu (VM lokal atau VPS)
- Install Nginx, Node.js atau PHP sesuai kebutuhan
- Deploy aplikasi web ke `/var/www/proyekmu`
- Konfigurasi Nginx dan aktifkan HTTPS
- Upload screenshot dan dokumentasi proses
Referensi
- [Nginx Docs](https://nginx.org/en/docs/)
- [Node.js + PM2 Deployment](https://pm2.keymetrics.io/docs/)
- [Laravel Deployment Guide](https://laravel.com/docs/deployment)
- [Let's Encrypt + Certbot](https://certbot.eff.org/instructions)