By creating virtual host each domain that is configured will direct the visitor to a specific directory holding that site's information, never indicating that the same server is also responsible for other sites.
Prerequisites
sudo apt-get updatesudo apt-get install apache21. Create the Directory Structure
Our document root will be set to individual directories under the /var/www directory. We will create a directory here for both of the virtual hosts we plan on making. we will create a public_html folder that will hold our actual files. This gives us some flexibility in our hosting.
sudo mkdir -p /var/www/mysite.com/public_html2. Grant Permissions
sudo chown -R $USER:$USER /var/www/mysite.com/public_htmlWe should modify permission to ensure a read access is permitted to general web directory.sudo chmod -R 755 /var/www3. Create Demo Pages for Virtual Host
vi /var/www/example.com/public_html/index.htmlPut below code in index.htmlWelcome to Mysite.com!Success! The mysite.com virtual host is working!
4. Create New Virtual Host Files
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.com.confsudo nano /etc/apache2/sites-available/mysite.com.conf
File will look like below.
ServerAdmin webmaster@localhostDocumentRoot /var/www/htmlErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${APACHE_LOG_DIR}/access.log combinedNeed to add below code in fileServerName mysite.comServerAlias www.mysite.comAnd set document root as DocumentRoot /var/www/mysite.com/public_html5. Enable the New Virtual Host Files
We can use a2ensite tool for enable configuration file.
sudo a2ensite mysite.com.conf6. Set Up Local Hosts File (Optional)
sudo nano /etc/hosts127.0.0.1 localhost
127.0.0.1 mysite.com
7. Test your URL
By same way you can add multiple domains in single server and you can handle multiple domain by this configuration.

