Difference between revisions of "Proses deployment aplikasi web menggunakan Apache"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "Berikut adalah **modul lengkap** untuk bagian **"Proses Deployment Aplikasi Web menggunakan Apache"**, sebagai bagian dari kuliah **Pengenalan Deployment Aplikasi Web** untuk...")
 
 
Line 1: Line 1:
−
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.
+
==Tujuan Pembelajaran:==
 +
Setelah mempelajari modul ini, mahasiswa mampu:
 +
* Menginstal dan mengonfigurasi Apache Web Server
 +
* Meletakkan dan menjalankan aplikasi web di server
 +
* Mengatur virtual host dan domain lokal
 +
* Mengamankan aplikasi dengan hak akses file yang tepat
  
−
---
+
==Persiapan Awal==
  
−
## 📘 Modul: Proses Deployment Aplikasi Web menggunakan Apache di Ubuntu 24.04
+
'''Sistem:'''
 +
* Ubuntu Server/Desktop 24.04
 +
* Akses sudo
 +
* Aplikasi web berbasis PHP/HTML/CSS/JS
  
−
### 🎯 Tujuan Pembelajaran
+
==1. Instalasi Apache Web Server==
−
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.
 
  
−
---
+
'''Langkah:'''
  
−
## 🧱 1. Instalasi dan Persiapan Awal
+
sudo apt update
 +
sudo apt install apache2 -y
  
−
### 1.1 Update Sistem
+
'''Cek Status:'''
−
```bash
 
−
sudo apt update && sudo apt upgrade -y
 
−
```
 
  
−
### 1.2 Install Apache2
+
sudo systemctl status apache2
−
```bash
 
−
sudo apt install apache2 -y
 
−
```
 
  
−
### 1.3 Uji Apache di Browser
+
> Akses `http://localhost` atau IP server di browser → harus muncul "Apache2 Ubuntu Default Page"
−
Buka browser dan akses IP server:
 
−
```
 
−
http://IP_ADDRESS
 
−
```
 
−
Jika muncul halaman "Apache2 Ubuntu Default Page", maka Apache berhasil terinstall.
 
  
−
---
+
==2. Instalasi Pendukung (untuk PHP Project)==
  
−
## 🔥 2. Keamanan Dasar Server
+
sudo apt install php libapache2-mod-php php-mysql -y
  
−
### 2.1 Aktifkan UFW (Firewall)
+
'''Cek Versi PHP:'''
−
```bash
 
−
sudo ufw allow OpenSSH
 
−
sudo ufw allow 'Apache Full'
 
−
sudo ufw enable
 
−
sudo ufw status
 
−
```
 
  
−
---
+
php -v
  
−
## 🌐 3. Struktur Direktori Produksi
+
==3. Struktur Direktori Web==
−
Apache menyimpan file website di:
 
−
```
 
−
/var/www/html
 
−
```
 
  
−
Namun, untuk produksi lebih rapi digunakan:
+
'''Lokasi default:'''
−
```
 
−
/var/www/
 
−
    ├── web1.com/
 
−
    ├── web2.com/
 
−
```
 
  
−
Contoh:
+
`/var/www/html/`
−
```bash
 
−
sudo mkdir -p /var/www/contohsite
 
−
sudo chown -R $USER:$USER /var/www/contohsite
 
−
```
 
  
−
---
+
'''Ganti isi default:'''
  
−
## 🧪 4. Deploy Website Statis (HTML, CSS, JS)
+
sudo rm /var/www/html/index.html
 +
sudo nano /var/www/html/index.php
  
−
### 4.1 Buat File HTML
+
'''Isi contoh:'''
−
```bash
 
−
nano /var/www/contohsite/index.html
 
−
```
 
  
−
```html
+
<pre>
−
<!DOCTYPE html>
+
<?php
−
<html>
+
echo "Halo dunia dari Apache!";
−
<head><title>Contoh Website</title></head>
+
?>
−
<body><h1>Halo Dunia dari Apache!</h1></body>
+
</pre>
−
</html>
 
−
```
 
  
−
### 4.2 Buat Virtual Host untuk Website
+
Akses di browser: `http://localhost`
−
```bash
 
−
sudo nano /etc/apache2/sites-available/contohsite.conf
 
−
```
 
  
−
```apache
+
==4. Deploy Aplikasi Web Sederhana==
−
<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
+
Misal folder aplikasi bernama `projectku`, letakkan di `/var/www/`
−
```bash
 
−
sudo a2ensite contohsite.conf
 
−
sudo systemctl reload apache2
 
−
```
 
  
−
Tambahkan di `/etc/hosts` lokal agar bisa diuji:
+
sudo cp -r ~/projectku /var/www/projectku
−
```
 
−
127.0.0.1 contohsite.local
 
−
```
 
  
−
Akses di browser: `http://contohsite.local`
+
==5. Konfigurasi Virtual Host (Multiple Projects)==
  
−
---
+
'''Buat File Config Baru:'''
  
−
## 🐘 5. Deploy Aplikasi PHP
+
sudo nano /etc/apache2/sites-available/projectku.conf
  
−
### 5.1 Install PHP
+
Isi contoh:
−
```bash
 
−
sudo apt install php libapache2-mod-php -y
 
−
```
 
  
−
### 5.2 Buat File PHP
+
<VirtualHost *:80>
−
```bash
+
    ServerAdmin webmaster@localhost
−
sudo nano /var/www/contohsite/index.php
+
    DocumentRoot /var/www/projectku
−
```
+
    ServerName projectku.local
 +
 +
    <Directory /var/www/projectku>
 +
        Options Indexes FollowSymLinks
 +
        AllowOverride All
 +
        Require all granted
 +
    </Directory>
 +
 +
    ErrorLog ${APACHE_LOG_DIR}/projectku_error.log
 +
    CustomLog ${APACHE_LOG_DIR}/projectku_access.log combined
 +
</VirtualHost>
  
−
```php
+
'''Aktifkan Virtual Host:'''
−
<?php
 
−
echo "Halo dari PHP!";
 
−
?>
 
−
```
 
  
−
### 5.3 Uji di browser
+
sudo a2ensite projectku.conf
−
`http://contohsite.local/index.php`
+
sudo systemctl reload apache2
  
−
---
+
'''(Opsional) Tambah ke `/etc/hosts` untuk domain lokal:'''
  
−
## 🐍 6. Deploy Aplikasi Flask (Python)
+
sudo nano /etc/hosts
  
−
### 6.1 Install Python dan WSGI
+
Tambahkan:
−
```bash
 
−
sudo apt install python3 python3-pip python3-venv libapache2-mod-wsgi-py3 -y
 
−
```
 
  
−
### 6.2 Setup Project
+
127.0.0.1    projectku.local
−
```bash
 
−
cd /var/www
 
−
python3 -m venv flaskenv
 
−
source flaskenv/bin/activate
 
−
pip install flask
 
−
```
 
  
−
### 6.3 Buat Struktur Aplikasi
+
> Sekarang akses `http://projectku.local` di browser
−
```bash
 
−
mkdir -p /var/www/flaskapp
 
−
cd /var/www/flaskapp
 
−
```
 
  
−
**wsgi.py**
 
−
```python
 
−
from app import app as application
 
−
```
 
  
−
**app.py**
+
==6. Set Hak Akses Folder==
−
```python
 
−
from flask import Flask
 
−
app = Flask(__name__)
 
  
−
@app.route("/")
+
sudo chown -R www-data:www-data /var/www/projectku
−
def hello():
+
sudo chmod -R 755 /var/www/projectku
−
    return "Halo Dunia dari Flask via Apache WSGI!"
 
−
```
 
  
−
### 6.4 Konfigurasi Apache
+
==7. Tambahan: HTTPS dengan Let's Encrypt==
−
```bash
 
−
sudo nano /etc/apache2/sites-available/flaskapp.conf
 
−
```
 
  
−
```apache
+
Jika menggunakan domain publik:
−
<VirtualHost *:80>
 
−
    ServerName flaskapp.local
 
  
−
    WSGIDaemonProcess flaskapp threads=5 python-home=/var/www/flaskenv
+
sudo apt install certbot python3-certbot-apache -y
−
    WSGIScriptAlias / /var/www/flaskapp/wsgi.py
+
sudo certbot --apache -d namadomainkamu.com
  
−
    <Directory /var/www/flaskapp>
+
==Praktik Mahasiswa==
−
        Require all granted
 
−
    </Directory>
 
  
−
    ErrorLog ${APACHE_LOG_DIR}/flaskapp_error.log
+
'''Tugas Praktik'''
−
    CustomLog ${APACHE_LOG_DIR}/flaskapp_access.log combined
+
* Install Apache di Ubuntu lokal atau server
−
</VirtualHost>
+
* Deploy proyek web pribadi (HTML/PHP)
−
```
+
* Konfigurasi virtual host dengan domain lokal (`.local`)
 +
* Berikan screenshot hasil deploy + isi file konfigurasi
  
−
```bash
+
'''Laporan'''
−
sudo a2ensite flaskapp.conf
+
* Penjelasan tahapan deploy
−
sudo systemctl reload apache2
+
* Struktur file proyek
−
```
+
* Kode virtual host (`.conf`)
 +
* Link GitHub (jika proyek open-source)
  
−
Tambahkan ke `/etc/hosts`:
+
==Referensi==
−
```
 
−
127.0.0.1 flaskapp.local
 
−
```
 
  
−
Akses di browser: `http://flaskapp.local`
+
* [Apache2 Ubuntu Docs](https://ubuntu.com/server/docs/web-servers-apache)
 +
* [DigitalOcean – Apache Virtual Hosts](https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu)
 +
* [Let's Encrypt Certbot](https://certbot.eff.org/instructions)
  
−
---
 
  
−
## 🛡️ 7. Menambahkan SSL dengan Let's Encrypt
+
==Pranala Menarik==
  
−
### 7.1 Install Certbot
+
* [[Web Programming]]
−
```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.
 

Latest revision as of 11:46, 8 April 2025

Tujuan Pembelajaran:

Setelah mempelajari modul ini, mahasiswa mampu:

  • Menginstal dan mengonfigurasi Apache Web Server
  • Meletakkan dan menjalankan aplikasi web di server
  • Mengatur virtual host dan domain lokal
  • Mengamankan aplikasi dengan hak akses file yang tepat

Persiapan Awal

Sistem:

  • Ubuntu Server/Desktop 24.04
  • Akses sudo
  • Aplikasi web berbasis PHP/HTML/CSS/JS

1. Instalasi Apache Web Server

Langkah:

sudo apt update
sudo apt install apache2 -y

Cek Status:

sudo systemctl status apache2

> Akses `http://localhost` atau IP server di browser → harus muncul "Apache2 Ubuntu Default Page"

2. Instalasi Pendukung (untuk PHP Project)

sudo apt install php libapache2-mod-php php-mysql -y

Cek Versi PHP:

php -v

3. Struktur Direktori Web

Lokasi default:

`/var/www/html/`

Ganti isi default:

sudo rm /var/www/html/index.html
sudo nano /var/www/html/index.php

Isi contoh:

 <?php
 echo "Halo dunia dari Apache!";
 ?>

Akses di browser: `http://localhost`

4. Deploy Aplikasi Web Sederhana

Misal folder aplikasi bernama `projectku`, letakkan di `/var/www/`

sudo cp -r ~/projectku /var/www/projectku

5. Konfigurasi Virtual Host (Multiple Projects)

Buat File Config Baru:

sudo nano /etc/apache2/sites-available/projectku.conf

Isi contoh:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/projectku
    ServerName projectku.local

    <Directory /var/www/projectku>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/projectku_error.log
    CustomLog ${APACHE_LOG_DIR}/projectku_access.log combined
</VirtualHost> 

Aktifkan Virtual Host:

sudo a2ensite projectku.conf
sudo systemctl reload apache2

(Opsional) Tambah ke `/etc/hosts` untuk domain lokal:

sudo nano /etc/hosts

Tambahkan:

127.0.0.1    projectku.local

> Sekarang akses `http://projectku.local` di browser


6. Set Hak Akses Folder

sudo chown -R www-data:www-data /var/www/projectku
sudo chmod -R 755 /var/www/projectku

7. Tambahan: HTTPS dengan Let's Encrypt

Jika menggunakan domain publik:

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d namadomainkamu.com

Praktik Mahasiswa

Tugas Praktik

  • Install Apache di Ubuntu lokal atau server
  • Deploy proyek web pribadi (HTML/PHP)
  • Konfigurasi virtual host dengan domain lokal (`.local`)
  • Berikan screenshot hasil deploy + isi file konfigurasi

Laporan

  • Penjelasan tahapan deploy
  • Struktur file proyek
  • Kode virtual host (`.conf`)
  • Link GitHub (jika proyek open-source)

Referensi


Pranala Menarik