Instalasi Apache Web Server di Debian 12
Apache adalah web server open-source berkinerja tinggi yang banyak digunakan untuk menyajikan aplikasi web statis maupun dinamis. Dengan dukungan modul yang ekstensif, Apache dapat diintegrasikan dengan PHP, SSL, dan berbagai backend aplikasi.
Panduan ini mencakup instalasi Apache di Debian 12, pembuatan virtual host, dan pengamanan dengan sertifikat SSL Let's Encrypt.
Prasyaratโ
- Server Debian 12 โ tersedia sebagai Nusa Cloud VPS dari nusa.id cloud
- Akses SSH sebagai user non-root dengan sudo
- Domain atau subdomain yang mengarah ke IP server (untuk virtual host dan SSL)
Update Paketโ
sudo apt update
sudo apt upgrade -y
Instalasi Apacheโ
sudo apt install apache2 -y
Verifikasi versi yang terinstal:
apachectl -v
Output contoh:
Server version: Apache/2.4.62 (Debian)
Server built: 2025-01-15T12:00:00
Mengizinkan Traffic HTTP di Firewallโ
Jika menggunakan UFW, izinkan port 80:
sudo ufw allow 80/tcp
sudo ufw reload
Mengelola Service ApacheGunakan systemctl untuk mengelola service Apache:โ
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2
Output yang diharapkan:
โ apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since ...
Perintah lain:
| Perintah | Fungsi |
|---|---|
sudo systemctl stop apache2 | Menghentikan Apache |
sudo systemctl restart apache2 | Restart Apache |
sudo systemctl reload apache2 | Reload konfigurasi tanpa putus koneksi |
Membuat Virtual Hostโ
Virtual host memungkinkan satu server melayani beberapa domain.
1. Nonaktifkan default siteโ
sudo a2dissite 000-default.conf
2. Buat konfigurasi virtual hostโ
sudo nano /etc/apache2/sites-available/nusa-app.conf
Isi dengan konfigurasi berikut โ ganti app.example.com dengan domain Anda:
<VirtualHost *:80>
ServerAdmin admin@app.example.com
ServerName app.example.com
ServerAlias www.app.example.com
DocumentRoot /var/www/app.example.com
<Directory /var/www/app.example.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/app.example.com-error.log
CustomLog ${APACHE_LOG_DIR}/app.example.com-access.log combined
</VirtualHost>
3. Aktifkan site dan buat direktoriโ
sudo mkdir -p /var/www/app.example.com
sudo chown -R www-data:www-data /var/www/app.example.com
sudo chmod -R 755 /var/www/app.example.com
sudo a2ensite nusa-app.conf
sudo apache2ctl configtest
Pastikan output: Syntax OK
4. Buat file index.html sampleโ
echo "<h1>Selamat Datang di Nusa Cloud VPS</h1>" | sudo tee /var/www/app.example.com/index.html
5. Restart Apacheโ
sudo systemctl restart apache2
Mengamankan dengan SSL (Let's Encrypt)โ
Instal Certbot untuk mendapatkan sertifikat SSL gratis:
sudo apt install snapd -y
sudo snap install certbot --classic
sudo certbot --apache -d app.example.com -d www.app.example.com
Ikuti petunjuk di layar. Certbot akan secara otomatis:
- Memvalidasi kepemilikan domain
- Mendapatkan sertifikat SSL
- Memperbarui konfigurasi Apache
Verifikasiโ
- Buka
http://app.example.comโ harus menampilkan halaman "Selamat Datang" - Buka
https://app.example.comโ koneksi harus aman dengan gembok SSL
Kesimpulanโ
Apache web server sudah terinstal dan berjalan di Debian 12 dengan virtual host aktif dan SSL terpasang. Server siap melayani aplikasi web Anda.
