Reading:
How To Setup A Virtual Host On Ubuntu

How To Setup A Virtual Host On Ubuntu

Metamug
How To Setup A Virtual Host On Ubuntu

Setup a virtual host for your website so that visitors will see different content depending on which page they visit. This way, you can use multiple domains (websites) on the same server without having to set up separate servers. This allows you to create multiple websites on a single server without having to use separate IP addresses.

What is a virtual host?

A virtual host allows you to run more than one website on a single web server by using separate configuration files. This means you can configure each site with its own domain name, IP address, and other settings. You can also make changes to the same configuration file for multiple sites at once.

Prerequisites

  • Hosting Account
  • A Server to host your website.

If you're running Ubuntu Linux, you can install Apache 2.0 by typing sudo apt-get install apache2 into the terminal window. You should then restart your computer before continuing with the rest of the steps.

If you want to create a new domain name for your site, you must first install a web server. The easiest way to do this is to download and install the latest version of Apache from http://httpd.apache.org/. You can then configure Apache to work with your domain name using Virtual Hosts. A virtual host allows you to create multiple websites on one physical machine. For example, if you own www.example.com, you could create a second website called www.example2.com. To accomplish this, you would need to create two virtual hosts. One virtual host would be configured to handle requests for www.example.com and the other would be configured to handle www.example2.

Add subdomain name in domain manager

Here we are going to use Godaddy as domain manager. You can use other domain registrar.

Godaddy update DNS

  • Login to your godaddy account and go to DNS
  • Go to your hosted zone i.e(your domain name) and create a recordset.
  • Add your domain name that you wish to create for ex:- example.metamug.net and then add the server address to it.

You can also do IP mapping with godaddy or any other provider if you are registered with them.

Godaddy add subdomain

Server setup on Ubuntu

  • Upload your website folder on ubuntu server on this location /var/www/

Example Folder

Add a conf file in apache2 folder on this location /etc/apache2/sites-available/ name it example.metamug.net.conf

<VirtualHost *:80>

    ServerName example.metamug.net 
    DocumentRoot /var/www/example.metamug.net 

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

    <Directory /var/www/example.metamug.net >
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
    </Directory>

</VirtualHost>

Add above code in your conf file i.e example.metamug.net.conf and save it.

Enable your conf file i.e example.metamug.net.conf and then restart your apache2 server

sudo a2ensite example.metamug.net.conf
sudo service apache2 restart

Log on to your website http://example.metamug.net

Enabling SSL on virtual host

Once the virtual host is setup. You can enable SSL using Lets Encrypt.



Icon For Arrow-up
Comments

Post a comment