Nambah Virtual Host Apache

Create a new directory in /var/www/ for your domain. Just replace mydomain.com with your own.

sudo mkdir -p /var/www/mydomain.com

8.2. Create Virtual Host
Create a virtual host configuration file replacing mydomain.com with your own.

sudo nano /etc/apache2/sites-available/mydomain.com.conf

Enter the following replacing mydomain.com with your own.

<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and exit (press CTRL + X, press Y and then press ENTER)

Test for errors.

apachectl configtest

You can ignore any error that mentions “Could not reliably determine the server’s fully qualified domain name”.

Enable your virtual host replacing mydomain.com with your own.

sudo a2ensite mydomain.com.conf

Disable the default Apache website, otherwise it will override your virtual host.

sudo a2dissite 000-default

Restart Apache.

sudo systemctl reload apache2

 

Leave a Comment