Apa itu Apache ?
Apache HTTP Server adalah perangkat lunak server web opensource dibawah lisensi Apache 2.0. Apache dikembangkan oleh Apache Software Foundation bersama dengan komunitasnya.
Beberapa distro linux memberikan nama yang berbeda, misalnya CentOS menggunakan httpd sebagai webserver apache, dan Ubuntu menggunakan apache2 sebagai webserver apache.
Apa itu VHOST ?
VHOST atau Virtual Host adalah konfigurasi pada webserver yang memungkinkan untuk menggunakan lebih dari satu domain pada web server.
Install Apache
Lakukan koneksi melalui SSH pada server, dan pastikan login sebagai root
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@iaasweb ~]# yum -y install httpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile epel/x86_64/metalink | 3.8 kB 00:00:00 * base: mirror.idroot.cloud * epel: epel.mirror.angkasa.id * extras: mirror.beon.co.id * updates: mirror.beon.co.id base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/3): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (2/3): epel/x86_64/primary_db | 7.0 MB 00:00:00 (3/3): updates/7/x86_64/primary_db | 18 MB 00:00:02 Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-97.el7.centos.5 will be installed |
Tambahkan rule firewall untuk http dan https agar webserver apache dapat dibuka pada browser melalui port 80 atau http
1 2 3 | [root@iaasweb ~]# firewall-cmd --permanent --zone=public --add-service=http [root@iaasweb ~]# firewall-cmd --permanent --zone=public --add-service=https [root@iaasweb ~]# firewall-cmd --reload |
Cek status apache kemudian start dan enable, fungsinya agar membuat mode persistent ketika server reboot maka apache otomatis akan running
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | [root@iaasweb ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd(8) man:apachectl(8) [root@iaasweb ~]# systemctl enable httpd && systemctl start httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@iaasweb ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2022-11-16 04:23:45 EST; 3s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 7585 (httpd) Status: "Processing requests..." CGroup: /system.slice/httpd.service ├─7585 /usr/sbin/httpd -DFOREGROUND ├─7586 /usr/sbin/httpd -DFOREGROUND ├─7587 /usr/sbin/httpd -DFOREGROUND ├─7588 /usr/sbin/httpd -DFOREGROUND ├─7589 /usr/sbin/httpd -DFOREGROUND └─7590 /usr/sbin/httpd -DFOREGROUND Nov 16 04:23:42 iaasweb.iaas.web.id systemd[1]: Starting The Apache HTTP Server... Nov 16 04:23:45 iaasweb.iaas.web.id systemd[1]: Started The Apache HTTP Server. |
Akses melalui browser dan ketikkan http://namadomain.com atau http://alamat.ip.server disini saya menggunakan domain dan melakukan editing pada file hosts untuk di targetkan ke IP

Konfigurasi VHOST Apache (Virtual Host)
Buat direktori sites-available dan sites-enabled
1 | [root@iaasweb ~]# mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled |
Tambahkan script berikut pada bagian paling bawah di httpd.conf
1 2 3 4 5 6 7 | [root@iaasweb ~]# nano /etc/httpd/conf/httpd.conf ... . ... # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf IncludeOptional sites-enabled/*.conf |
Buat file vhost untuk domain pada direktori sites-available
1 2 3 4 5 6 7 8 9 | [root@iaasweb ~]# nano /etc/httpd/sites-available/subdomain.iaas.web.id.conf <VirtualHost *:80> ServerName www.subdomain.iaas.web.id ServerAlias subdomain.iaas.web.id DocumentRoot /var/www/subdomain.iaas.web.id/html ErrorLog /var/www/subdomain.iaas.web.id/error.log CustomLog /var/www/subdomain.iaas.web.id/requests.log combined </VirtualHost> [root@iaasweb ~]# ln -s /etc/httpd/sites-available/subdomain.iaas.web.id.conf /etc/httpd/sites-enabled/subdomain.iaas.web.id.conf |
Buat folder dan file untuk subdomain agar dapat digunakan sebagai tempat menyimpan isi file website, setelah vhost dan beberapa folder/file terbuat maka langkah berikutnya restart web server
1 2 3 4 5 | [root@iaasweb ~]# mkdir /var/www/subdomain.iaas.web.id [root@iaasweb ~]# mkdir /var/www/subdomain.iaas.web.id/html [root@iaasweb ~]# touch /var/www/subdomain.iaas.web.id/error.log [root@iaasweb ~]# touch /var/www/subdomain.iaas.web.id/requests.log [root@iaasweb ~]# systemctl restart httpd |
Buat file index.html untuk subdomain
1 2 | [root@iaasweb ~]# nano /var/www/subdomain.iaas.web.id/html/index.html <h1>Subdomain Created Succesfully</h1> |
Akses melalui browser dan ketikkan http://subdomain.namadomain.com disini saya menggunakan domain dan melakukan editing pada file hosts untuk di targetkan ke IP
