Praktik: Men-deploy aplikasi web ke server produksi
Jump to navigation
Jump to search
Tujuan Pembelajaran:
Setelah praktik ini, mahasiswa mampu:
- Memahami konsep deployment aplikasi web ke server
- Menyiapkan server Ubuntu 24.04 untuk produksi
- Mengupload dan menjalankan aplikasi web di server
- Mengatur domain, web server (Apache/Nginx), dan HTTPS
Persiapan
Alat yang Dibutuhkan:
- Server Ubuntu 24.04 (bisa VPS atau VirtualBox)
- Akses root atau user sudo
- Aplikasi web (HTML, PHP, Laravel, React, dll.)
- Akses terminal (SSH)
- (Opsional) Nama domain
Langkah 1: Siapkan Server
Update Server
sudo apt update && sudo apt upgrade -y
Instalasi Web Server
- Jika pakai PHP:
sudo apt install apache2 php libapache2-mod-php unzip -y
- Jika pakai Node.js:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install nodejs -y
Langkah 2: Upload Aplikasi ke Server
Opsi 1: Pakai SCP (dari lokal ke server)
scp -r /path/proyekmu user@ip_server:/var/www/proyekmu
Opsi 2: Pakai Git
sudo apt install git -y cd /var/www/ git clone https://github.com/username/proyekmu.git
Langkah 3: Konfigurasi Web Server
- Untuk Apache (PHP/HTML):
sudo nano /etc/apache2/sites-available/proyekmu.conf
Contoh isi:
<VirtualHost *:80> ServerName proyekmu.local DocumentRoot /var/www/proyekmu <Directory /var/www/proyekmu> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Aktifkan dan reload:
sudo a2ensite proyekmu.conf sudo systemctl reload apache2
- Untuk Node.js (pakai PM2 + Nginx):
npm install -g pm2 pm2 start npm --name "proyekmu" -- start pm2 save
Konfigurasi Nginx:
sudo nano /etc/nginx/sites-available/proyekmu
Contoh:
server { listen 80; server_name domainmu.com; location / { proxy_pass http://localhost:3000; 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:
sudo ln -s /etc/nginx/sites-available/proyekmu /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
Langkah 4: Tambahkan HTTPS (Let's Encrypt)
sudo apt install certbot python3-certbot-apache -y sudo certbot --apache -d domainmu.com
> Untuk Nginx, ganti `--apache` menjadi `--nginx`
Tugas Praktik Mahasiswa
Tujuan:
Melakukan deployment aplikasi web ke server produksi
Langkah Praktik:
- Pilih aplikasi web statis (HTML/CSS/JS) atau dinamis (PHP/Node.js)
- Deploy ke server Ubuntu menggunakan salah satu metode (Apache atau Nginx)
- Konfigurasi domain lokal (via `/etc/hosts`) atau domain publik (jika tersedia)
- Tambahkan SSL gratis dari Let's Encrypt
Dokumentasi yang Dikumpulkan:
- Screenshot hasil akses web dari browser
- Salinan konfigurasi server (`*.conf`)
- Link GitHub proyek (jika ada)
- Penjelasan tahapan dan kendala
Referensi
- [Apache Virtual Host Docs](https://httpd.apache.org/docs/current/vhosts/)
- [Nginx Docs](https://nginx.org/en/docs/)
- [PM2 Node Process Manager](https://pm2.keymetrics.io/)
- [Certbot by Let’s Encrypt](https://certbot.eff.org/instructions)