Membuat Virtual Host di Mac
Posted on: January 16, 2013 /
Apaan sih virtual Host??
The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com
andcompany2.example.com
) on a single machine. Virtual hosts can be “IP-based“, meaning that you have a different IP address for every web site, or “name-based“, meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.
Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.
sumber
Kenapa harus pake Virtual Host??
biar mac kita serasa server beneran. dan kangen aja sama linux.
Langkah 1
Karena saya telah membuat settingan apache yang mungin berbeda dari versi yang ada (disini).
seluruh setting apache milik saya berada di /opt/local/apache2/
sehingga saya memerlukan setting yang berbeda pula. namun untuk versi yang asli atau tetap menggunakan milik mac asli file berada di /private/etc/apache2
atau tutorial bisa dilihat disini
Buat alamat domain yang anda inginkan di
/etc/hosts
Lakukan dengan mengedit file tersebut (dengan file editor kesayangan anda)
{code type=shell}sudo vi /etc/hosts{/code}
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 dewi.cantik
172.16.168.128 bisma
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
dalam contoh diatas saya menambahkan domain dewi.cantik dan nantinya akan dijadikan nama domain.
Langkah 2
Buka dan edit file di
/opt/local/apache2/conf/extra/httpd-vhosts.conf
file tersebut adalah dimana anda melakukan penambahan configurasi pada virtual web anda. dan file itu bersinonim dengan file /etc/apache2/site-available/namaVirtualHost
Lakukan dengan mengedit file tersebut (dengan file editor kesayangan anda)
{code type=shell}sudo vi /opt/local/apache2/conf/extra/httpd-vhosts.conf{/code}
dan saya menambahkan baris dibawah ini pada akhir file, dan untuk yang lain bisa di comment. dan silahkan dimodifikasi sesuai kebutuhan anda
{code}
<VirtualHost *:80>
DocumentRoot “/Users/rahadianbisma/repo_git”
ServerName dewi.cantik
</VirtualHost>
{/code}
DocumentRoot adalah lokasi dari file applikasi yang akan anda tempatkan
ServerName adalah nama domain disesuaikan dengan yang di /etc/hosts
lalu kita harus mengenable kan vhost yang telah kita buat dengan cara edit file /opt/local/apache2/conf/httpd.conf
{code}sudo vi /opt/local/apache2/conf/httpd.conf{/code}
cari bagian
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
dan hilangkan tanda #
Langkah 3
restart Apache using the command below (type it into Terminal):
sudo apache2ctl restart
tergantung setting anda