Proses deployment aplikasi web menggunakan Apache
Berikut adalah **modul lengkap** untuk bagian **"Proses Deployment Aplikasi Web menggunakan Apache"**, sebagai bagian dari kuliah **Pengenalan Deployment Aplikasi Web** untuk mata kuliah **Web Programming**. Modul ini dirancang untuk **Ubuntu 24.04** dan **tidak menggunakan tools dari Microsoft sama sekali**. Banyak contoh konkret disertakan agar mudah dipahami oleh mahasiswa.
---
- 📘 Modul: Proses Deployment Aplikasi Web menggunakan Apache di Ubuntu 24.04
- 🎯 Tujuan Pembelajaran
Setelah mengikuti modul ini, mahasiswa diharapkan mampu: - Menginstall dan mengkonfigurasi Apache sebagai web server. - Men-deploy aplikasi web berbasis HTML, PHP, dan Python (Flask) menggunakan Apache. - Mengatur virtual host untuk lebih dari satu website. - Menerapkan pengamanan dasar dan struktur produksi.
---
- 🧱 1. Instalasi dan Persiapan Awal
- 1.1 Update Sistem
```bash sudo apt update && sudo apt upgrade -y ```
- 1.2 Install Apache2
```bash sudo apt install apache2 -y ```
- 1.3 Uji Apache di Browser
Buka browser dan akses IP server: ``` http://IP_ADDRESS ``` Jika muncul halaman "Apache2 Ubuntu Default Page", maka Apache berhasil terinstall.
---
- 🔥 2. Keamanan Dasar Server
- 2.1 Aktifkan UFW (Firewall)
```bash sudo ufw allow OpenSSH sudo ufw allow 'Apache Full' sudo ufw enable sudo ufw status ```
---
- 🌐 3. Struktur Direktori Produksi
Apache menyimpan file website di: ``` /var/www/html ```
Namun, untuk produksi lebih rapi digunakan: ``` /var/www/
├── web1.com/ ├── web2.com/
```
Contoh: ```bash sudo mkdir -p /var/www/contohsite sudo chown -R $USER:$USER /var/www/contohsite ```
---
- 🧪 4. Deploy Website Statis (HTML, CSS, JS)
- 4.1 Buat File HTML
```bash nano /var/www/contohsite/index.html ```
```html <!DOCTYPE html> <html> <head><title>Contoh Website</title></head>
<body>
Halo Dunia dari Apache!
</body>
</html> ```
- 4.2 Buat Virtual Host untuk Website
```bash sudo nano /etc/apache2/sites-available/contohsite.conf ```
```apache <VirtualHost *:80>
ServerAdmin admin@contohsite.local ServerName contohsite.local DocumentRoot /var/www/contohsite ErrorLog ${APACHE_LOG_DIR}/contohsite_error.log CustomLog ${APACHE_LOG_DIR}/contohsite_access.log combined
</VirtualHost> ```
- 4.3 Aktifkan Virtual Host
```bash sudo a2ensite contohsite.conf sudo systemctl reload apache2 ```
Tambahkan di `/etc/hosts` lokal agar bisa diuji: ``` 127.0.0.1 contohsite.local ```
Akses di browser: `http://contohsite.local`
---
- 🐘 5. Deploy Aplikasi PHP
- 5.1 Install PHP
```bash sudo apt install php libapache2-mod-php -y ```
- 5.2 Buat File PHP
```bash sudo nano /var/www/contohsite/index.php ```
```php <?php echo "Halo dari PHP!"; ?> ```
- 5.3 Uji di browser
`http://contohsite.local/index.php`
---
- 🐍 6. Deploy Aplikasi Flask (Python)
- 6.1 Install Python dan WSGI
```bash sudo apt install python3 python3-pip python3-venv libapache2-mod-wsgi-py3 -y ```
- 6.2 Setup Project
```bash cd /var/www python3 -m venv flaskenv source flaskenv/bin/activate pip install flask ```
- 6.3 Buat Struktur Aplikasi
```bash mkdir -p /var/www/flaskapp cd /var/www/flaskapp ```
- wsgi.py**
```python from app import app as application ```
- app.py**
```python from flask import Flask app = Flask(__name__)
@app.route("/") def hello():
return "Halo Dunia dari Flask via Apache WSGI!"
```
- 6.4 Konfigurasi Apache
```bash sudo nano /etc/apache2/sites-available/flaskapp.conf ```
```apache <VirtualHost *:80>
ServerName flaskapp.local
WSGIDaemonProcess flaskapp threads=5 python-home=/var/www/flaskenv WSGIScriptAlias / /var/www/flaskapp/wsgi.py
<Directory /var/www/flaskapp> Require all granted </Directory>
ErrorLog ${APACHE_LOG_DIR}/flaskapp_error.log CustomLog ${APACHE_LOG_DIR}/flaskapp_access.log combined
</VirtualHost> ```
```bash sudo a2ensite flaskapp.conf sudo systemctl reload apache2 ```
Tambahkan ke `/etc/hosts`: ``` 127.0.0.1 flaskapp.local ```
Akses di browser: `http://flaskapp.local`
---
- 🛡️ 7. Menambahkan SSL dengan Let's Encrypt
- 7.1 Install Certbot
```bash sudo apt install certbot python3-certbot-apache -y ```
- 7.2 Jalankan
```bash sudo certbot --apache ```
---
- 🧠 Tips Produksi
- Pastikan **permission** direktori `755`, file `644`. - Log aplikasi dapat dicek di `/var/log/apache2/` - Gunakan `.env` file untuk menyimpan konfigurasi rahasia.
---
- 🧪 Tugas Praktikum
1. Deploy website HTML sederhana menggunakan Apache. 2. Deploy aplikasi PHP dengan formulir input sederhana. 3. Deploy aplikasi Python Flask menggunakan WSGI dan Apache. 4. Tambahkan konfigurasi VirtualHost dan akses melalui domain lokal. 5. (Opsional) Uji deployment dengan SSL dari Let's Encrypt.
---
Kalau kamu mau aku bantu konversi modul ini ke **PDF / DOCX / Markdown / format kuliah lainnya**, tinggal bilang. Bisa juga dibuat per bab untuk silabus mingguan.