Iklan 728x90

Cara Membuat Virtual Host di Apache2 Webserver Mudah dan Simpel



Apache Web Server merupakan salah satu web server yang paling banyak di minati, karena kemudahan konfigurasi kita tinggal copy file konfigurasi virtual host dari file default. Web server apache salah satu web server tertua yang di rilis tahun 1995, apache sendiri ada versi Windows dan Linux. Dalam tutorial kali ini konfigurasi di tetakankan pada OS Linux Debian Server.

Fungsi dari Virtual Host untuk mengatur banyak website di dalam satu server, misalnya kita punya banyak domain tapi hanya memiliki satu IP Public atau 1 Server, cara agar website tersebut bisa jalan dan di akses di internet maka digunakan Virtual Host pada web server. 

Untuk konfigurasi domain kita bisa menggunakan layanan Bind9, dari domain tersebut setiap pengunjung website akan di arahkan mengakses virtual directory yang berbeda beda. Konten setiap directory tidak sama seperti CMS atau framework.

Cara Konfigurasi

1. Install Apache Webserver,  mysql-server, phpmyadmin. untuk user dan password mysql-server saya menggunakan root

#apt-get install apache2
#apt-get install mysql-server
#apt-get install phpmyadmin

2. Buka localhost dengan web browser akan tampil default web page apache jika instalasi berhasil


Bisa kita lihat directory default untuk halaman web ada  di /var/www/html/index.html

3. Untuk konfigurasi Virtual Host sendiri, ada pada direktory /etc/apache2/sites-available dengan nama file 000-default.conf

4. Konfigurasi Virtual Host, saya membuat 2 virtual host untuk 2 Website

#cd /etc/apache2/sites-available
#cp 000-default.conf 000-website1.conf
#cp 000-default.conf 000-website2.conf

5. Beriku ini file 000-default.conf Virtual Host

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com # yang di ubah
ServerAdmin webmaster@localhost # yang di ubah
DocumentRoot /var/www/html # yang di ubah
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

6. Silahkan Ubah untuk website1 yakni 000-website1.conf, di atas sudah ada keterangannya

#pico 000-website1.conf
ServerName www.website1.com
ServerAlias website1.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/website1/wordpress

7. Silahkan Ubah untuk website2 yakni 000-website1.conf, di atas sudah ada keterangannya

#pico 000-website2.conf
ServerName www.website2.com
ServerAlias website2.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/website2/wordpress

8. Membuat directory untuk masing masing website

mkdir /var/www/html/website1/wordpress
mkdir /var/www/html/website2/wordpress

9. Sediakan wordpress pada directory /home, di sini wordpress dalam satu folder sudah saya upload ke directory /home

cd /home
cp -R wordpress /var/www/html/website1/wordpress
cp -R wordpress /var/www/html/website2/wordpress

10. Membuat database wordpress untuk masing masing website.

#mysql –u root –p
create database website1;
create database website2;
exit;
11. Pindah directory ke /var/www/html/website1/wordpress
#cd /var/www/html/website1/wordpress
#cp wp-config-sample.php wp-config.php
#pico  wp-config.php
isi parameter berikut ini
(‘DB_NAME’,’website1’);
(‘DB_USER’,’root’);
(‘DB_PASSWORD’,’root’);
12. Pindah directory ke /var/www/html/website2/wordpress
#cd /var/www/html/website2/wordpress
#cp wp-config-sample.php wp-config.php
#pico  wp-config.php
isi parameter berikut ini
(‘DB_NAME’,’website2’);
(‘DB_USER’,’root’);
(‘DB_PASSWORD’,’root’);
13. Aktifkan semua virtualhost dan restart apache2
#a2ensite 000-website1.conf
#a2ensite 000-website2.conf
#a2dissite 000-default.conf

13. Reload dan restart apache2

#/etc/init.d/apache2 reload
#/etc/init.d/apache2 restart

14. Setelah konfigurasi diatas selesai, silahkan akses masing-masing website akan muncul parameter instalasi wordpress.

Sekian konfigurasi virtual host untuk web server apache2, saya menggunakan OS Debian. Semoga tutorial ini bermanfaat bagi anda yang sedang membangun website. Semoga berguna.


Post a Comment

0 Comments