Apache2 dengan Virtual Hosts di Ubuntu Server


copas dari : http://www.paidjo.com/linux/apache2-dengan-virtual-hosts-di-ubuntu-server

Apache2 dengan Virtual Hosts di Ubuntu Server

Apache2 dengan Virtual Hosts di Ubuntu Server yang akan saya bahas dan sebagai catatan saya sendiri :D :D
Mungkin ada beberapa perbedaan saat menggunakan virtual host di Ubuntu Server dengan Plaform Linux lain seperti CentOS ataupun Fedora, itu sih yang pernah saya coba. Perbedaan yang terletak pada setting Virtual Hosts yang dibutuhkan beberapa tahapan bila di Ubuntu, sedangkan untuk CentOS dan Fedora hanya create file dan diarah virtual hosts ke file tersebut.
Sebelumnya silahkan bikin folder/directory untuk menentukan letak web, misalnya
cd /var/www/
sudo mkdir –p sites/paidjo.com
sudo mkdir sites/paidjo.com/log
sudo chmod –R 755 sites/paidjo.com
dimana web diletakkan pada folder paidjo.com
cd sites/paidjo.com
sudo nano –w index.html
masukkan script untuk testingnya
<html>
  <head>
    <title>Web PAIDJO.COM</title>
  </head>
  <body>
    This Web PAIDJO.COM
  </body>
</html>
Setelah membuat file index.html sebagai testing, sekarang kita membuat file untuk virtual hosts nya, seperti berikut saya membuat file config virtual host dengan vhost-paidjo.com
sudo nano –w /etc/apache2/sites-available/vhost-paidjo.com
berikut isi script untuk file vhost-paidjo.com
    <virtualhost *:80>
      # Admin email, Server Name (domain name) and any aliases
      ServerAdmin webmaster@paidjo.com
      ServerName  paidjo.com
      ServerAlias www.paidjo.com

      # Index file and Document Root (where the public files are located)
      DirectoryIndex index.html
      DocumentRoot /var/www/sites/paidjo.com

      # Custom log file locations
      LogLevel warn
      ErrorLog  /var/www/sites/paidjo.com/log/error.log
      CustomLog /var/www/sites/paidjo.com/log/access.log combined

    </virtualhost>

Setelah file vhost-paidjo.com sudah dibuat, sekarang enable file vhost-paidjo.com dengan perintah
sudo a2ensite <nama file virtual hostnya>
sudo a2ensite vhost-paidjo.com
status vhost-paidjo.com akan enable silahkan reload ulang apache2 nya
sudo /etc/init.d/apache2 reload
Silahkan dicoba untuk browsingnya dengan alamat url www.paidjo.com atau paidjo.com

Untuk menghapus virtual hosts lakukan disable terlebih dahulu file virtual hostsnya sebelum menghapus file virtual hosts
sudo a2dissite vhost-paidjo.com
reload apache2 nya
sudo /etc/init.d/apache2 reload
kemudian baru hapus file virtual hostsnya
sudo rm /etc/apache2/sites-available/vhost-paidjo.com
Perhatikan tahap untuk menghapusnya kalau tidak ingin terjadi error pada apache2.

Subscribe to receive free email updates:

0 Response to "Apache2 dengan Virtual Hosts di Ubuntu Server"

Post a Comment