Skip to content

Instantly share code, notes, and snippets.

@abumaryam
Created March 19, 2020 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abumaryam/069cc132744e738cef8db91362ef2abe to your computer and use it in GitHub Desktop.
Save abumaryam/069cc132744e738cef8db91362ef2abe to your computer and use it in GitHub Desktop.
Konfigurasi Apache Untuk Virtual Host

Cara Membuat Virtual Host pada Apache

  • Buat File pada direktori /etc/apache2/sites-available/ dengan mengetikkan perintah (pada contoh ini kita akan menambahkan virtual host dengan nama pwduadian)
sudo nano /etc/apache2/sites-available/pwduadian.conf
  • Masukkan file konfigurasi seperti yang ada pada file pwduadian.conf yang ada pada Gist ini. Yang perlu menjadi perhatian bahwa pada baris ke 2 dan 18 harus diubah sesuai dengan direktori web anda. karena kita menggunakan laravel, jangan lupa untuk mengarahkannya pada direktori public. Kemudian pada baris ke 15 silahkan anda edit sesuai dengan nama virtualhost anda. Dalam contoh tersebut adalah pwdua.local . Sehingga nanti ketika web anda diakses ada pada alamat http://pwdua.local

  • Tambahkan nama pwdua.local dan ip address yang sama dengan localhost. Perhatikan contoh file hosts pada gist ini.

  • Jalankan perintah untuk aktifasi

sudo a2ensite pwduadian.conf
sudo service apache2 reload

Demikian semoga bermanfaat

127.0.0.1 localhost
127.0.0.1 pwdua.local
<VirtualHost *:80>
<Directory /var/www/html/pwduadian/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
# 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 pwdua.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/pwduadian/public
# 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>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment