Last updated on August 28th, 2020 at 05:13 pm

In this tutorial I am going to explain to you how we can point a domain name to our website which was hosting in Apache server in simple steps.

Setup A Virtual Host in Apache server

Step 1. Hope you already installed Apache in your server. If not then please run below commands to do.

sudo apt-get update
sudo apt-get install apache2

Step 2. Now create your project in /var/www/html/myproject.com. For now, I just create an index.html file in it and write hello.

<html>
  <head>
    <title>TrinityTuts</title>
  </head>
  <body>
    <h1>Helo</h1>
  </body>
</html>

Step 3. Now we can point a domain to our server I am using Cloudflare for that. In Cloudflare, you need to add a domain to your account then go to DNS setting and point the domain to your IP that’s it.

Step 4. Now go to /etc/apache2/sites-available and copy 000-default.conf and name that mydomain.com.conf

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mydomain.com.conf

Step 5. Open copy file in the editor and make some required changes as shown below.

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

After the file was open make changes or just copy below code and replace mydomain.com with yours.

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName mydomain.com
        ServerAlias www.mydomain.com
        DocumentRoot /var/www/html/mydomain.com

        <Directory /var/www/html/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

</VirtualHost>

Step 6. Now once you make changes in your file then you need to enable your website to do that run below command

sudo a2ensite mydomain.com.conf

After that restart your Apache server

sudo systemctl restart apache2

and once your server is restarted you can open your website in the browser and get “helo” page.

Hope this simple ost helps you 🙂 .