Untuk menjaga kerjaan kita sebagai programmer web yang profesional agar tetap rapi di localhost, membuat virtual host merupakan langkah awal yang baik. Apalagi kalau kita mempunyai pekerjaan yang banyak. Nah apa itu virtual host dan bagaimana caranya membuat virtual host …
Apa itu virtual host?
Virtualhost adalah host buatan atau simulasi host pada server apache atau localhost. Secara default alamat host server kita adalah http://localhost/bla..bla.. Kita bisa membuat host buatan untuk simulasi seperti host server beneran. Misalkan, kita pengen membuat nama virtual host dengan nama http://latihan1.com. Dengan virtual host nantinya kita bisa membuat lebih dari satu domain yang mana kita simpan di direktori C:\WWW.
Bagaimana cara membuatnya?
Cara membuatnya sangat mudah, ikuti saja langkah2 dibawah ini. Saya hanya mencobanya di Xampp, jadi sebaiknya anda yang ingin mencoba juga menggunakan Xampp 🙂 .
Langkah-langkahnya :
- Instal XAMPP (Pastikan semua service bisa berjalan)
- Buka file host yang ada di C:\WINDOWS\system32\drivers\etc
- Edit file host dan tambahkan virtual host di dalam file tersebut (lihat contoh di bawah), lalu save:
> file host sebelum di ubah:# Copyright (c) 1993-2006 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows. #
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host127.0.0.1 localhost
::1 localhost
Misal kita ingin menambahkan virtual host baru : 127.0.0.1 simakel.com dibawah localhost (lihat contoh dibawah)
# Copyright (c) 1993-2006 Microsoft Corp.# # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host127.0.0.1 localhost
::1 localhost
127.0.0.1 simakel.com
Kita juga bisa menambahkan virtualhost lebih dari satu, ulangi langkah ke tiga jika ingin menambahkan virtualhost lagi.
- Buka file httpd.conf yang ada di C:\xampp\apache\conf, lalu ubah directory permission supaya bisa diakses oleh siapapun. (lihat contoh dibawah)
Cari kode dibawah:<Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory>
Lalu ganti dengan kode dibawah:
<Directory "C:/www"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory>
Save file tersebut.
- Lalu buka lagi file httpd-vhosts.conf yang ada di C:\xampp\apache\conf\extra, tambahkan ServerName dan DocumentRoot pada file tersebut. (lihat contoh dibawah) .
Cari NameVirtualHost, lalu hilangkan komentarnya (##), jadi seperti dibawah:##NameVirtualHost *:80
Lalu ganti dengan kode dibawah:
NameVirtualHost *:80
Tambahkan virtualhost Anda yang terdiri dari ServerName dan DocumentRoot.
#VirtualHost Anda <VirtualHost *:80> DocumentRoot C:/www/simakel.com ServerName simakel.com </VirtualHost> #Untuk membedakan localhost dengan virtualHost Anda: <VirtualHost *:80> DocumentRoot C:/xampp/htdocs ServerName localhost </VirtualHost>Save file tersebut.
- Finally, buat folder dengan nama simakel.com di directori: C:\www
Selamat …. Anda sudah memiliki virtual host, Jika anda ingin membuat virtual host yang baru, ulangi langkah2 di atas dari awal. Semoga membantu ….
Nah, virtual host ini akan di gunakan di tutorial selanjutnya yaitu tentang pembuatan aplikasi web dengan CodeIgniter Framework.
Thanks 🙂 .