{"id":17138,"date":"2022-10-31T17:07:07","date_gmt":"2022-10-31T11:37:07","guid":{"rendered":"https:\/\/www.milesweb.in\/hosting-faqs\/?p=17138"},"modified":"2022-11-02T16:14:48","modified_gmt":"2022-11-02T10:44:48","slug":"how-to-configure-apache-virtual-hosts-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/","title":{"rendered":"How to Configure Apache Virtual Hosts on Ubuntu 20.04?"},"content":{"rendered":"\n<p>The Apache HTTP web server is one of the popular open-source web servers which offers the power, flexibility and support for developers.<\/p>\n\n\n\n<p>Now, using the virtual hosts, one Apache instance can serve different website. Every domain or an individual website configured using the Apache will direct the visitor to a particular directory holding that website\u2019s information. This is done without suggesting the user that the same server is also responsible for other websites.<\/p>\n\n\n\n<p>This article describes the steps to configure Apache virtual host on Ubuntu 20.04 server.<\/p>\n\n\n\n<p><strong>Prerequisites:<\/strong><\/p>\n\n\n\n<p>Make sure that you have met the below requirements before continuing the guide.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>One or more domain names that are pointing to your public server IP.<\/li><li>Apache installed on Ubuntu system.<\/li><li>You\u2019re logged in as root or user with sudo privileges.<\/li><\/ul>\n\n\n\n<p>The first step is to create a directory structure that consists of the site data that you will show to the visitors.<\/p>\n\n\n\n<p>Document root, the top-level directory that Apache looks at to<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps for Creating Virtual Hosts<\/h2>\n\n\n\n<p>On Ubuntu systems, the Apache Virtual Hosts configuration files are all located in the \/etc\/apache2\/sites-available directory. They can be easily enabled by creating the symbolic links to the <strong><em>\/etc\/apache2\/sites-<\/em><\/strong>enabled directory, which Apache generally reads during the initial phase.<\/p>\n\n\n\n<p>Now, open the text editor of your choice and create the below Virtual Host configuration file.<\/p>\n\n\n\n<p><em><strong>\/etc\/apache2\/sites-available\/test1.com.conf<\/strong><\/em><\/p>\n\n\n\n<p><strong><em>&lt;VirtualHost *:80&gt;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;<\/em><\/strong><em>&nbsp; ServerName<\/em> test1.com<\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;<\/em><\/strong><em>&nbsp; ServerAlias www.test1.com<\/em><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp; <\/em><\/strong><em>ServerAdmin webmaster@test1.com<\/em><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;<\/em><\/strong><em>&nbsp; DocumentRoot \/var\/www\/<em>test1<\/em>.com\/public_html<\/em><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp; <\/em><\/strong><em>&lt;Directory \/var\/www\/<em><em>test1<\/em><\/em>.com\/public_html&gt;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options -Indexes +FollowSymLinks<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AllowOverride All<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp; &lt;\/Directory&gt;<\/em><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp; <\/em><\/strong><em>ErrorLog ${APACHE_LOG_DIR}\/<em><em><em>test1<\/em><\/em><\/em>.com-error.log<\/em><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;<\/em><\/strong><em> CustomLog ${APACHE_LOG_DIR}\/<em><em><em>test1<\/em><\/em><\/em>.com-access.log combined<\/em><\/p>\n\n\n\n<p><em><strong>&lt;\/VirtualHost&gt;<\/strong><\/em><br><br><strong>Note:<\/strong> You can even create a virtual host for subdomain.<\/p>\n\n\n\n<p>Knowing the components of Virtual Host:<\/p>\n\n\n\n<p><strong>ServerName:<\/strong> The domain that needs to match for this virtual host configuration. This also needs to be your domain name.<\/p>\n\n\n\n<p><strong>ServerAlias:<\/strong> All the other domains or subdomains that needs to be matched for this virtual host such as www subdomain.<\/p>\n\n\n\n<p><strong>DocumentRoot:<\/strong> It is basically the directory from which&nbsp; the Apache will serve the domain files.<\/p>\n\n\n\n<p><strong>Options:<\/strong> This directive particularly controls the server features available in the specific directory.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>FollowSymLinks:<\/strong> When you enable this option, Apache will follow the symbolic links.<\/li><li><strong>Indexes:<\/strong> Prevents the directory listings.<\/li><\/ul>\n\n\n\n<p><strong>AllowOverride:<\/strong> It specifies which directives declared in the .htaccess file can override the configuration directives.<\/p>\n\n\n\n<p><strong>ErrorLog, CustomLog:<\/strong> Basically, specifies the location for log files.<\/p>\n\n\n\n<p>You can name the configuration files according to your choice, but the best way is to use the domain name of the virtual host configuration file.<\/p>\n\n\n\n<p>After this, you have to enable the new virtual host file. To do so, <strong><em>a2ensite <\/em><\/strong>helper script that creates symbolic link from the virtual host file to the <strong><em>sites-enabled directory:<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>sudo a2ensite <em><em><em>test1<\/em><\/em><\/em>.com<\/em><\/strong><\/p>\n\n\n\n<p>One more option is, you can manually create a symlink as given below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>sudo ln -s \/etc\/apache2\/sites-available\/<em><em><em>test1<\/em><\/em><\/em>.com.conf \/etc\/apache2\/sites-enabled\/<\/em><\/strong><\/code><\/pre>\n\n\n\n<p>Once this is done, test the configuration for the syntax errors with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>$ sudo apachetl2 configtest<\/em><\/strong><\/code><\/pre>\n\n\n\n<p>If no errors are found, you will then get to see the below output.<\/p>\n\n\n\n<p><strong><em>Output<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>Syntax OK<\/em><\/strong><\/p>\n\n\n\n<p>Restart the Apache service for the changes to appear:<\/p>\n\n\n\n<p><strong><em>$ sudo systemctl restart apache<\/em>2<\/strong><\/p>\n\n\n\n<p>To verify that everything works as expected, open http:\/\/test1.com in your browser and you will get to see the content of the <strong><em>index.html<\/em><\/strong> page.<\/p>\n\n\n\n<p>Here is the success message you get:<\/p>\n\n\n\n<p><strong>Success! test1.com home page!<\/strong><\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>You have a single server handling two different domain names. You can also expand the process by following the steps given in the above tutorial to add the virtual hosts. There is no restriction on the number of domain names Apache can handle, so you can easily make as many virtual hosts as your server is capable to handle.<\/p>\n\n\n\n<p>Repeat the steps to create virtual hosts for all your domains.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Apache HTTP web server is one of the popular open-source web servers which offers the power, flexibility and support for developers. Now, using the virtual hosts, one Apache instance can serve different website. Every domain or an individual website configured using the Apache will direct the visitor to a particular directory holding that website\u2019s [&hellip;]<\/p>\n","protected":false},"author":36,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[2963],"class_list":["post-17138","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-vps-faq","tag-apache-virtual-hosts-on-ubuntu-20-04"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Configure Apache Virtual Hosts on Ubuntu 20.04?<\/title>\n<meta name=\"description\" content=\"In this guide lets understand the steps to configure Apache Virtual Hosts on Ubuntu 20.04.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Configure Apache Virtual Hosts on Ubuntu 20.04?\" \/>\n<meta property=\"og:description\" content=\"In this guide lets understand the steps to configure Apache Virtual Hosts on Ubuntu 20.04.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-31T11:37:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-02T10:44:48+00:00\" \/>\n<meta name=\"author\" content=\"Nehal Khatri\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nehal Khatri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/\"},\"author\":{\"name\":\"Nehal Khatri\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb\"},\"headline\":\"How to Configure Apache Virtual Hosts on Ubuntu 20.04?\",\"datePublished\":\"2022-10-31T11:37:07+00:00\",\"dateModified\":\"2022-11-02T10:44:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/\"},\"wordCount\":687,\"commentCount\":0,\"keywords\":[\"Apache Virtual Hosts on Ubuntu 20.04\"],\"articleSection\":[\"VPS FAQ\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/\",\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/\",\"name\":\"How to Configure Apache Virtual Hosts on Ubuntu 20.04?\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#website\"},\"datePublished\":\"2022-10-31T11:37:07+00:00\",\"dateModified\":\"2022-11-02T10:44:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb\"},\"description\":\"In this guide lets understand the steps to configure Apache Virtual Hosts on Ubuntu 20.04.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.in\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure Apache Virtual Hosts on Ubuntu 20.04?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.in\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb\",\"name\":\"Nehal Khatri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/wp-content\/uploads\/2022\/02\/nehal-khatri-150x150.png\",\"contentUrl\":\"https:\/\/www.milesweb.in\/hosting-faqs\/wp-content\/uploads\/2022\/02\/nehal-khatri-150x150.png\",\"caption\":\"Nehal Khatri\"},\"description\":\"Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.\",\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/author\/nehal-khatri\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Configure Apache Virtual Hosts on Ubuntu 20.04?","description":"In this guide lets understand the steps to configure Apache Virtual Hosts on Ubuntu 20.04.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure Apache Virtual Hosts on Ubuntu 20.04?","og_description":"In this guide lets understand the steps to configure Apache Virtual Hosts on Ubuntu 20.04.","og_url":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2022-10-31T11:37:07+00:00","article_modified_time":"2022-11-02T10:44:48+00:00","author":"Nehal Khatri","twitter_misc":{"Written by":"Nehal Khatri","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#article","isPartOf":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/"},"author":{"name":"Nehal Khatri","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb"},"headline":"How to Configure Apache Virtual Hosts on Ubuntu 20.04?","datePublished":"2022-10-31T11:37:07+00:00","dateModified":"2022-11-02T10:44:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/"},"wordCount":687,"commentCount":0,"keywords":["Apache Virtual Hosts on Ubuntu 20.04"],"articleSection":["VPS FAQ"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/","url":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/","name":"How to Configure Apache Virtual Hosts on Ubuntu 20.04?","isPartOf":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#website"},"datePublished":"2022-10-31T11:37:07+00:00","dateModified":"2022-11-02T10:44:48+00:00","author":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb"},"description":"In this guide lets understand the steps to configure Apache Virtual Hosts on Ubuntu 20.04.","breadcrumb":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-ubuntu-20-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.in\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"How to Configure Apache Virtual Hosts on Ubuntu 20.04?"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.in\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.in\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb","name":"Nehal Khatri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-content\/uploads\/2022\/02\/nehal-khatri-150x150.png","contentUrl":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-content\/uploads\/2022\/02\/nehal-khatri-150x150.png","caption":"Nehal Khatri"},"description":"Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.","url":"https:\/\/www.milesweb.in\/hosting-faqs\/author\/nehal-khatri\/"}]}},"_links":{"self":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/17138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=17138"}],"version-history":[{"count":10,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/17138\/revisions"}],"predecessor-version":[{"id":17170,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/17138\/revisions\/17170"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=17138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=17138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=17138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}