{"id":60443,"date":"2024-02-26T12:26:08","date_gmt":"2024-02-26T06:56:08","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=60443"},"modified":"2024-02-27T12:28:13","modified_gmt":"2024-02-27T06:58:13","slug":"create-a-virtual-host-on-ubuntu-machine-in-simple-way","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/create-a-virtual-host-on-ubuntu-machine-in-simple-way\/","title":{"rendered":"Create a virtual host on Ubuntu Machine in simple way"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>A virtual host refers to the practice of hosting multiple domain names on a single server or multiple servers. It allows a single physical server to serve multiple websites, each with its own domain name and content. Virtual hosting is commonly used in web hosting environments to efficiently utilize server resources and accommodate multiple websites on a single server.<\/p>\n<h3>Step 1: Install Apache Web Server on your local machine<\/h3>\n<p>Install Apache Web Server on your local machine If you haven&#8217;t already, install the Apache web server on<br \/>\nyour Ubuntu server:<\/p>\n<h3>Step 1:<\/h3>\n<pre><strong>       sudo apt update\r\n       sudo apt install apache2\r\n       sudo ufw allow 'Apache'\r\n       sudo ufw enable\r\n<\/strong><\/pre>\n<p>When you have your server\u2019s IP address, enter it into your browser\u2019s address bar:<\/p>\n<p>http:\/\/your_server_ip <strong>or<\/strong> http:\/\/localhost<\/p>\n<p><strong>You will see the default Ubuntu 22.04 Apache web page as in the following:<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"818\" height=\"1023\" class=\"alignnone size-medium wp-image-60421\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-26-00.png\" alt=\"\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-26-00.png 818w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-26-00-240x300.png 240w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-26-00-768x960.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-26-00-624x780.png 624w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><\/p>\n<h3>Step 2: Configure Virtual Host<\/h3>\n<p>Copy localhost configuration file and paste it on same place then make it a new virtual host configuration<br \/>\nfile for your domain using a text editor like <strong>VSCODE<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"927\" height=\"247\" class=\"alignnone size-medium wp-image-60422\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-30-31.png\" alt=\"\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-30-31.png 927w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-30-31-300x80.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-30-31-768x205.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-30-31-624x166.png 624w\" sizes=\"(max-width: 927px) 100vw, 927px\" \/><\/p>\n<div>\n<pre>&lt;VirtualHost *:80&gt;\r\n\r\n# The ServerName directive sets the request scheme, hostname and port that\r\n\r\n# the server uses to identify itself. This is used when creating\r\n\r\n# redirection URLs. In the context of virtual hosts, the ServerName\r\n\r\n# specifies what hostname must appear in the request's Host: header to\r\n\r\n# match this virtual host. For the default virtual host (this file) this\r\n\r\n# value is not decisive as it is used as a last resort host regardless.\r\n\r\n# However, you must set it for any further virtual host explicitly.\r\n\r\nServerName local.vr.com\r\n\r\nServerAdmin webmaster@localhost\r\n\r\nDocumentRoot \/var\/www\/html\/myvrhost\r\n\r\n# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,\r\n\r\n# error, crit, alert, emerg.\r\n\r\n# It is also possible to configure the loglevel for particular\r\n\r\n# modules, e.g.\r\n\r\n#LogLevel info ssl:warn\r\n\r\nErrorLog ${APACHE_LOG_DIR}\/error.log\r\n\r\nCustomLog ${APACHE_LOG_DIR}\/access.log combined\r\n\r\n# For most configuration files from conf-available\/, which are\r\n\r\n# enabled or disabled at a global level, it is possible to\r\n\r\n# include a line for only one particular virtual host. For example the\r\n\r\n# following line enables the CGI configuration for this host only\r\n\r\n# after it has been globally disabled with \"a2disconf\".\r\n\r\n#Include conf-available\/serve-cgi-bin.conf\r\n\r\n&lt;\/VirtualHost&gt;\r\n\r\n# vim: syntax=apache ts=4 sw=4 sts=4 sr noet<\/pre>\n<\/div>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"800\" height=\"689\" class=\"alignnone size-medium wp-image-60423\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-33-35.png\" alt=\"\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-33-35.png 800w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-33-35-300x258.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-33-35-768x661.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-12-33-35-624x537.png 624w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3>Step 3: Enable the Virtual Host<\/h3>\n<pre><strong>            sudo a2ensite my-virtual-host.conf\r\n            sudo systemctl restart apache2\r\n<\/strong><\/pre>\n<h3>Step 4: Configure Hosts File<\/h3>\n<p>Open Termianl<strong> Crl+Alt+T<\/strong> and run the below command to pen host file<\/p>\n<pre><strong>            sudo code \/etc\/hosts\r\n<\/strong><\/pre>\n<p>Add a line like this, replacing your_server_ip with the actual IP address and local.vr.com with your domain.<\/p>\n<h3>Step 5: Create Directory Structure<\/h3>\n<p>For each virtual host, create a directory structure to hold the website&#8217;s files.<\/p>\n<pre><strong>\/var\/ww\/html\/myvrhost\/index.html<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"744\" height=\"116\" class=\"alignnone size-medium wp-image-60440\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-30-54.png\" alt=\"\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-30-54.png 744w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-30-54-300x47.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-30-54-624x97.png 624w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><\/p>\n<div>\n<pre>&lt;!DOCTYPE html&gt;\r\n\r\n&lt;html lang=\"en\"&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;metacharset=\"UTF-8\"&gt;\r\n\r\n&lt;metaname=\"viewport\"content=\"width=device-width, initial-scale=1.0\"&gt;\r\n\r\n&lt;title&gt;Document&lt;\/title&gt;\r\n\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;My virtual host&lt;\/h1&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/pre>\n<\/div>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"753\" height=\"277\" class=\"alignnone size-medium wp-image-60441\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-44-08.png\" alt=\"\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-44-08.png 753w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-44-08-300x110.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Screenshot-from-2024-02-23-14-44-08-624x230.png 624w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><\/p>\n<h3>Step 6: Verify the Virtual Host<\/h3>\n<p>Open a web browser and enter your domain (<strong>e.g.<\/strong> http:\/\/local.vr.com). You should see your website served by the newly configured virtual host.<\/p>\n<h3>Conclusion<\/h3>\n<p>This article begins with an introduction to virtual hosts, covering the fundamentals. It then explores various methods of configuring hosts.<\/p>\n<p>Check out our other blog posts for more insights. If you still have any questions, comment and join the discussion.<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Introduction A virtual host refers to the practice of hosting multiple domain names on a single server or multiple servers. It allows a single physical server to serve multiple websites, each with its own domain name and content. Virtual hosting is commonly used in web hosting environments to efficiently utilize server resources and accommodate multiple [&hellip;]<\/p>\n","protected":false},"author":1546,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":58},"categories":[1174,3602,3429,5021],"tags":[4862,4860,2591,1877],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60443"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1546"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=60443"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60443\/revisions"}],"predecessor-version":[{"id":60480,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60443\/revisions\/60480"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=60443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=60443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=60443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}