Install DVWA di Ubuntu Server - wongganteng10/tutorial GitHub Wiki
Pastikan sistem Anda up-to-date dengan menjalankan perintah berikut:
sudo apt update
sudo apt upgrade -y {opsional}
DVWA membutuhkan web server dan database. Instal Apache dan MySQL dengan perintah:
sudo apt install apache2 mysql-server -y
DVWA memerlukan PHP dan beberapa ekstensi. Instal PHP dan ekstensi dengan perintah:
sudo apt install php libapache2-mod-php php-mysql php-gd php-mbstring php-xml php-curl -y
Unduh DVWA dari GitHub:
cd /var/www/html
sudo git clone https://github.com/digininja/DVWA.git
Salin file konfigurasi contoh dan sesuaikan dengan konfigurasi Anda:
cd DVWA/config
sudo cp config.inc.php.dist config.inc.php
sudo nano config.inc.php
Ubah bagian berikut dalam file config.inc.php
sesuai dengan pengaturan MySQL Anda:
$_DVWA = array();
$_DVWA['db_database'] = 'dvwa'; // Ubah sesuai dengan database MySQL Anda
$_DVWA['db_user'] = 'dvwa'; // Ubah sesuai dengan user MySQL Anda
$_DVWA['db_password'] = 'p@ssw0rd'; // Masukkan password sesuai MySQL Anda
Masuk ke MySQL dan buat database untuk DVWA:
sudo mysql -u root -p
Di dalam MySQL, jalankan perintah berikut:
CREATE DATABASE dvwa;
CREATE USER 'dvwa'@'localhost' IDENTIFIED BY 'p@ssw0rd';
GRANT ALL PRIVILEGES ON dvwa.* TO 'dvwa'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Pastikan direktori DVWA dapat diakses oleh Apache:
sudo chown -R www-data:www-data /var/www/html/DVWA/
sudo chmod -R 755 /var/www/html/DVWA/
Restart Apache untuk menerapkan perubahan:
sudo systemctl restart apache2
Buat file konfigurasi untuk DVWA:
sudo nano /etc/apache2/sites-available/dvwa.conf
Tambahkan konfigurasi berikut:
<VirtualHost *:8082>
ServerAdmin [email protected]
DocumentRoot /var/www/DVWA
ServerName dvwa.co.id.com
ServerAlias www.dvwa.co.id.com
<Directory /var/www/DVWA/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Konfigurasi port pada ports.conf
sesuai dengan konfigurasi sites-available
DVWA-nya:
sudo nano /etc/apache2/ports.conf
Tambahkan Listen
dengan port sesuai dengan konfigurasi sites-available
DVWA-nya:
Listen 8082
Aktifkan konfigurasi baru dan modul rewrite:
sudo a2ensite dvwa.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
Buka browser dan akses DVWA melalui alamat:
http://your_server_ip/DVWA/setup.php
Ikuti instruksi di layar untuk menyelesaikan instalasi.
Sesuaikan pengaturan PHP untuk mengizinkan DVWA berjalan dengan baik. Buka file konfigurasi PHP dan sesuaikan:
sudo nano /etc/php/{Versi PHP}/apache2/php.ini
Contoh:
sudo nano /etc/php/7.4/apache2/php.ini
Pastikan pengaturan berikut sudah diaktifkan dan diatur dengan benar:
allow_url_include = On
allow_url_fopen = On
display_errors = Off
log_errors = On
Simpan dan tutup file (Ctrl+O
, Enter
, Ctrl+X
), lalu restart Apache lagi:
sudo systemctl restart apache2
Buka browser dan akses server Anda melalui IP atau domain (misalnya, http://example.com
). Anda akan melihat halaman instalasi DVWA. Ikuti instruksi untuk menyelesaikan instalasi dengan memasukkan detail database yang telah Anda buat sebelumnya.
Berikut adalah script .sh
untuk menginstal DVWA di Ubuntu Server secara otomatis:
#!/bin/bash
# Install DVWA di Ubuntu Server
# 1. Update Sistem
echo "Updating system..."
sudo apt update
sudo apt upgrade -y
# 2. Instal Apache dan MySQL
echo "Installing Apache and MySQL..."
sudo apt install apache2 mysql-server -y
# 3. Instal PHP dan Ekstensi yang Diperlukan
echo "Installing PHP and required extensions..."
sudo apt install php libapache2-mod-php php-mysql php-gd php-mbstring php-xml php-curl -y
# 4. Download DVWA
echo "Downloading DVWA..."
cd /var/www/html
sudo git clone https://github.com/digininja/DVWA.git
# 5. Konfigurasi File DVWA
echo "Configuring DVWA..."
cd DVWA/config
sudo cp config.inc.php.dist config.inc.php
# Edit config.inc.php (sesuaikan detail MySQL Anda di sini)
sudo sed -i "s/'db_user' = 'root'/'db_user' = 'dvwa'/g" config.inc.php
sudo sed -i "s/'db_password' = 'p@ssw0rd'/'db_password' = 'p@ssw0rd'/g" config.inc.php
# 6. Konfigurasi Database
echo "Configuring MySQL database..."
sudo mysql -u root -p <<MYSQL_SCRIPT
CREATE DATABASE dvwa;
CREATE USER 'dvwa'@'localhost' IDENTIFIED BY 'p@ssw0rd';
GRANT ALL PRIVILEGES ON dvwa.* TO 'dvwa'@'localhost';
FLUSH PRIVILEGES;
EXIT;
MYSQL_SCRIPT
# 7. Ubah Izin Direktori
echo "Setting permissions for DVWA directory..."
sudo chown -R www-data:www-data /var/www/html/DVWA/
sudo chmod -R 755 /var/www/html/DVWA/
# 8. Restart Apache
echo "Restarting Apache..."
sudo systemctl restart apache2
# 9. Konfigurasi Apache
echo "Configuring Apache for DVWA..."
sudo bash -c 'cat > /etc/apache2/sites-available/dvwa.conf <<EOF
<VirtualHost *:8082>
ServerAdmin [email protected]
DocumentRoot /var/www/html/DVWA
ServerName dvwa.local
<Directory /var/www/html/DVWA/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog \${APACHE_LOG_DIR}/dvwa_error.log
CustomLog \${APACHE_LOG_DIR}/dvwa_access.log combined
</VirtualHost>
EOF'
# 10. Konfigurasi Port Apache
echo "Configuring Apache ports..."
sudo bash -c 'echo "Listen 8082" >> /etc/apache2/ports.conf'
# 11. Aktifkan Virtual Host dan Modul Rewrite
echo "Enabling DVWA site and mod_rewrite..."
sudo a2ensite dvwa.conf
sudo a2enmod rewrite
# 12. Restart Apache
echo "Restarting Apache..."
sudo systemctl restart apache2
# 13. Konfigurasi PHP
echo "Configuring PHP settings..."
PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
sudo sed -i "s/allow_url_include = Off/allow_url_include = On/g" /etc/php/$PHP_VERSION/apache2/php.ini
sudo sed -i "s/display_errors = On/display_errors = Off/g" /etc/php/$PHP_VERSION/apache2/php.ini
# Restart Apache lagi
echo "Restarting Apache again..."
sudo systemctl restart apache2
echo "DVWA installation completed. Access it at http://your_server_ip:8082"
Cara menjalankan script ini:
- Simpan dengan nama
install_dvwa.sh
. - Jalankan perintah berikut untuk memberi izin eksekusi:
chmod +x install_dvwa.sh
- Jalankan script:
./install_dvwa.sh
Script ini akan secara otomatis melakukan instalasi DVWA sesuai instruksi yang kamu berikan.