Apache Web Server
Apache HTTP Server (sering disebut Apache) adalah salah satu web server paling populer di dunia.
Dikembangkan oleh Apache Software Foundation, Apache digunakan untuk melayani permintaan HTTP/HTTPS dari klien (biasanya browser) dan menampilkan halaman web.
Fungsi Utama Apache
- Menangani permintaan HTTP/HTTPS dari pengguna.
- Menyajikan file HTML, PHP, gambar, dan konten web lainnya.
- Mengatur virtual host (menjalankan beberapa situs di satu server).
- Menyediakan logging akses dan error.
- Mendukung modul tambahan seperti
mod_ssl,mod_rewrite, danmod_proxy.
Kelebihan Apache
- Open-source dan gratis.
- Sangat fleksibel dan modular.
- Kompatibel di berbagai sistem operasi (Linux, Windows, macOS).
- Dukungan komunitas luas dan dokumentasi lengkap.
Instalasi Apache Web Server
A. Ubuntu / Debian
sudo apt update
sudo apt install apache2 -y
B. CentOS / RHEL
sudo yum install httpd -y
sudo systemctl enable httpd
sudo systemctl start httpd
C. Alpine Linux
apk add apache2
rc-update add apache2
rc-service apache2 start
D. Verifikasi Instalasi
Setelah instalasi, cek status layanan:
sudo systemctl status apache2 # untuk Debian/Ubuntu
sudo systemctl status httpd # untuk CentOS/RHEL
Atau buka browser dan akses:
http://localhost
Jika muncul halaman bertuliskan “Apache2 Default Page”, maka instalasi berhasil.
Struktur Direktori Apache
| Lokasi | Fungsi |
|---|---|
/etc/apache2/ | Direktori utama konfigurasi Apache (Debian/Ubuntu) |
/etc/httpd/ | Direktori utama konfigurasi Apache (CentOS/RHEL) |
/var/www/html/ | Direktori default untuk file web |
/var/log/apache2/ | Log file Apache (access.log, error.log) |
/etc/apache2/sites-available/ | File konfigurasi virtual host |
/etc/apache2/sites-enabled/ | Virtual host yang aktif |
Konfigurasi Dasar Apache
A. Menjalankan Apache
sudo systemctl start apache2
sudo systemctl enable apache2
B. Mengatur Firewall (Opsional)
sudo ufw allow 'Apache Full'
sudo ufw reload
C. Mengubah Konten Default
Edit atau ganti file HTML default:
sudo nano /var/www/html/index.html
Isi contoh sederhana:
<html>
<head><title>Halo Dunia!</title></head>
<body><h1>Apache Server Berhasil Dijalankan 🚀</h1></body>
</html>
Lalu buka di browser:
http://localhost
Konfigurasi Virtual Host
Virtual Host memungkinkan kamu menjalankan beberapa website di satu server Apache.
A. Buat Direktori Website
sudo mkdir -p /var/www/contoh.local/public_html
sudo chown -R $USER:$USER /var/www/contoh.local/public_html
B. Buat File Index
echo "<h1>Selamat Datang di contoh.local!</h1>" > /var/www/contoh.local/public_html/index.html
C. Buat File Virtual Host
sudo nano /etc/apache2/sites-available/contoh.local.conf
Isi file:
<VirtualHost *:80>
ServerAdmin admin@contoh.local
ServerName contoh.local
DocumentRoot /var/www/contoh.local/public_html
ErrorLog ${APACHE_LOG_DIR}/contoh.local-error.log
CustomLog ${APACHE_LOG_DIR}/contoh.local-access.log combined
</VirtualHost>
D. Aktifkan Virtual Host
sudo a2ensite contoh.local.conf
sudo systemctl reload apache2
Tambahkan DNS lokal (untuk testing):
sudo nano /etc/hosts
Tambahkan baris:
127.0.0.1 contoh.local
Akses di browser:
http://contoh.local
Menambahkan HTTPS (SSL)
Gunakan Certbot untuk sertifikat SSL gratis dari Let's Encrypt.
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
Ikuti panduan interaktif untuk mengaktifkan HTTPS di domain kamu.
Mengelola Apache
| Perintah | Fungsi |
|---|---|
sudo systemctl start apache2 | Menjalankan Apache |
sudo systemctl stop apache2 | Menghentikan Apache |
sudo systemctl restart apache2 | Restart Apache |
sudo systemctl reload apache2 | Reload konfigurasi tanpa restart penuh |
sudo systemctl enable apache2 | Mengaktifkan Apache otomatis saat boot |
Log & Monitoring
File log Apache disimpan di:
/var/log/apache2/access.log
/var/log/apache2/error.log
Untuk melihat log secara langsung:
sudo tail -f /var/log/apache2/access.log
Kesimpulan
Apache Web Server adalah solusi open-source yang kuat dan fleksibel untuk menjalankan website.
Dengan konfigurasi yang sederhana, kamu dapat menjalankan satu atau banyak situs di satu server, menambahkan SSL, dan mengatur performa sesuai kebutuhan.