How to Create an Apache 2 Virtual Host on Debian 10 Buster Easy Guide

July 21, 2019 | By thelinuxevangelist | Filed in: Tutorial.

Setting Up

  1. 2. Editing Hosts

    Add the Domain to the hosts Config File

    sudo nano /etc/hosts

    If Got “User is Not in Sudoers file” then Look: Solution
    Append:

    127.0.0.1	[myDomainName.com]

    Just Substitute Your real Domain Name to “[myDomainName.com]” :)
    Ctrl+Shift+v to Paste Content into nano
    Ctrl+x to Save and Exit from nano Editor

  2. 3. Making VHost Folder

    Create the VHost Target Directory

    sudo mkdir /var/www/html/[myDomainName.com]

    And may be also a Testing index.html:

    sudo su -c 'echo "The New Web-Site is Working on Apache2!" >> /var/www/html/[mySite]/index.html'

    Then Set the Domain’s Ownership with:

    sudo chown -R www-data:www-data /var/www/html/[myDomainName.com]
  3. 4. Making VHost Config File

    Now Create a VHost Config File

    sudo nano /etc/apache2/sites-available/[myDomainName].conf

    Append at Least:

    <VirtualHost *:80>	
    ServerName	[myDomainName.com]
    ServerAlias	www.[myDomainName.com]
    DocumentRoot /var/www/html/[myDomainName.com]
    </VirtualHost>
    

    Eventually substitute the actual Port to 80.
    To get a little More Insight may look:

    cat /etc/apache2/sites-available/000-default.conf
  4. 5. Enabling VHost

    Enabling the New Virtual-Host

    cd /etc/apache2/sites-enabled
    sudo ln -s ../sites-available/[myDomainName].conf .

    Finally, Restart Apache2 Web Server

    sudo service apache2 restart
  5. How to Enable Apache2 mod_rewrite Module on Debian

    Enabling Apache2 Rewrite for Debian

    How to Create a IP-based Virtual Host on Linux Debian

    How to Create an IP-Based Virtual Host on Debian:

    Debian Apache2 IP Virtual-Host

Contents


Tags: , , , , , , , , , , , , , , , ,