{"id":17132,"date":"2022-10-31T17:21:50","date_gmt":"2022-10-31T11:51:50","guid":{"rendered":"https:\/\/www.milesweb.in\/hosting-faqs\/?p=17132"},"modified":"2022-11-02T16:16:40","modified_gmt":"2022-11-02T10:46:40","slug":"how-to-configure-apache-virtual-hosts-on-centos7","status":"publish","type":"post","link":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/","title":{"rendered":"How to Configure Apache Virtual Hosts on CentOS7?"},"content":{"rendered":"\n<p>Using Apache web server, you can host more than one domain on the same server using virtual hosts. Virtual hosting can host multiple websites on one web server. You can even specify the site document root (the directory that contains the website files), create a different security policy for every site, using SSL certificates for every site and much more.<\/p>\n\n\n\n<p>In this tutorial, we will get to know the steps to configure the steps to Configure Apache Virtual Host on CentOS 7.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction:<\/h2>\n\n\n\n<p>Apache is one of the most commonly used, free and open-source web server software that is used for running website\/applications. Nearly, around 40% websites use Apache web server.<\/p>\n\n\n\n<p><strong>Prerequisites:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You need to have a domain name which is pointing to your public server IP. Here we are using <strong><em>test.com.<\/em><\/strong><\/li><li>You are logged in as a user with sudo privileges.<\/li><li>You have Apache installed already.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Configure Apache Virtual Hosts on CentOS7.<\/h2>\n\n\n\n<p>The first step is to create a directory structure. <strong><em>DocumentRoot <\/em><\/strong>is the directory where all the website files for a domain name are stored and served in response to the requests. You can set the document root to the location you need.<\/p>\n\n\n\n<p>After creating the directory structure, you then have to create the virtual host file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating Virtual Host File<\/h3>\n\n\n\n<p>There are different ways through which you can set up a virtual host. You can even make separate file for every Virtual Host Directive or you can add all the Virtual Host Directives in a single file. It is also suggested to make separate files for every domain due to its maintainability.<\/p>\n\n\n\n<p>By default, Apache is configured to load all the configurations ending with <strong><em>.conf<\/em><\/strong> from the <strong><em>\/etc\/httpd\/conf.d\/<\/em><\/strong> directory.<\/p>\n\n\n\n<p>Now, to create a virtual host for a specific website open the editor of your choice and create the following basic Virtual Host Configuration file.<\/p>\n\n\n\n<p><strong>&lt;VirtualHost<\/strong> *:80<strong>&gt;<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; ServerName test.com<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; ServerAlias www.test.com<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; ServerAdmin milesweb@test.com<\/p>\n\n\n\n<p>\u00a0\u00a0\u00a0 DocumentRoot \/var\/www\/test.com\/public_html<\/p>\n\n\n\n<p>\u00a0\u00a0\u00a0 <strong>&lt;Directory<\/strong> \/var\/www\/test.com\/public_html<strong>><\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options -Indexes +FollowSymLinks<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AllowOverride <strong>All<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <strong>&lt;\/Directory&gt;<\/strong><\/p>\n\n\n\n<p>\u00a0\u00a0\u00a0 ErrorLog \/var\/log\/httpd\/test.com-error.log<\/p>\n\n\n\n<p>\u00a0\u00a0\u00a0 CustomLog \/var\/log\/httpd\/test.com-access.log combined<\/p>\n\n\n\n<p><strong>&lt;\/VirtualHost&gt;<\/strong><\/p>\n\n\n\n<p><strong><em>ServerName: <\/em><\/strong>This should be your domain name and need to match with the virtual host configuration.<\/p>\n\n\n\n<p><strong><em>ServerAlias: <\/em><\/strong>All the other domains or subdomains should match for this virtual host in addition with, usually the <strong><em>www<\/em><\/strong> subdomain.<\/p>\n\n\n\n<p><strong><em>DocumentRoot: <\/em><\/strong>It\u2019s the directory from which the Apache will serve the domain files.<\/p>\n\n\n\n<p><strong><em>Options: <\/em><\/strong>This directive controls the server features that are available in a specific directory.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><em>Indexes:<\/em><\/strong> Prevents the directory listings.<\/li><li><strong><em>FollowSymLinks:<\/em><\/strong> It tells your web server to follow the symbolic links.<\/li><\/ul>\n\n\n\n<p><strong><em>AllowOverride: <\/em><\/strong>Specifies whether the directives declared in the<strong><em> .htaccess <\/em><\/strong><em>file can<\/em>override theconfiguration<em> devices.<\/em><\/p>\n\n\n\n<p><strong><em>ErrorLog, CustomLog:<\/em><\/strong> It specifies the location for the log files.<\/p>\n\n\n\n<p>It\u2019s very important that the configuration file name ends with the <strong><em>.conf.<\/em><\/strong> Any names can be given to your configuration file, but it\u2019s recommended to use the domain name as the name of the virtual host configuration file.<\/p>\n\n\n\n<p>Now check the syntax by typing the command:<\/p>\n\n\n\n<p><strong><em>$ httpd -t<\/em><\/strong><\/p>\n\n\n\n<p>It will give you the below output if there are no errors.<\/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>Now, to activate the newly created virtual host, restart the Apache service with:<\/p>\n\n\n\n<p><strong><em>$ sudo systemctl restart httpd<\/em><\/strong><\/p>\n\n\n\n<p>You can verify by opening your <a href=\"http:\/\/test.com\">http:\/\/test.com<\/a> to your web browser and then it will show you the following message.<\/p>\n\n\n\n<p><strong><em>Success! test.com set up completed!<\/em><\/strong><\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>In this tutorial, we have explained the steps to create a Apache Virtual host on CentOs. You can repeat the steps given above and then create an additional virtual host for all your domains.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Apache web server, you can host more than one domain on the same server using virtual hosts. Virtual hosting can host multiple websites on one web server. You can even specify the site document root (the directory that contains the website files), create a different security policy for every site, using SSL certificates for [&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":[2962],"class_list":["post-17132","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-vps-faq","tag-apache-virtual-hosts-on-centos7"],"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 CentOS7?<\/title>\n<meta name=\"description\" content=\"In this guide, we will get to know the steps to configure Apache Virtual Host on CentOS 7.\" \/>\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-centos7\/\" \/>\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 CentOS7?\" \/>\n<meta property=\"og:description\" content=\"In this guide, we will get to know the steps to configure Apache Virtual Host on CentOS 7.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-31T11:51:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-02T10:46:40+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-centos7\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/\"},\"author\":{\"name\":\"Nehal Khatri\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb\"},\"headline\":\"How to Configure Apache Virtual Hosts on CentOS7?\",\"datePublished\":\"2022-10-31T11:51:50+00:00\",\"dateModified\":\"2022-11-02T10:46:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/\"},\"wordCount\":649,\"commentCount\":0,\"keywords\":[\"Apache Virtual Hosts on CentOS7\"],\"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-centos7\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/\",\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/\",\"name\":\"How to Configure Apache Virtual Hosts on CentOS7?\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#website\"},\"datePublished\":\"2022-10-31T11:51:50+00:00\",\"dateModified\":\"2022-11-02T10:46:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb\"},\"description\":\"In this guide, we will get to know the steps to configure Apache Virtual Host on CentOS 7.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/#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 CentOS7?\"}]},{\"@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 CentOS7?","description":"In this guide, we will get to know the steps to configure Apache Virtual Host on CentOS 7.","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-centos7\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure Apache Virtual Hosts on CentOS7?","og_description":"In this guide, we will get to know the steps to configure Apache Virtual Host on CentOS 7.","og_url":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2022-10-31T11:51:50+00:00","article_modified_time":"2022-11-02T10:46:40+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-centos7\/#article","isPartOf":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/"},"author":{"name":"Nehal Khatri","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb"},"headline":"How to Configure Apache Virtual Hosts on CentOS7?","datePublished":"2022-10-31T11:51:50+00:00","dateModified":"2022-11-02T10:46:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/"},"wordCount":649,"commentCount":0,"keywords":["Apache Virtual Hosts on CentOS7"],"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-centos7\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/","url":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/","name":"How to Configure Apache Virtual Hosts on CentOS7?","isPartOf":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#website"},"datePublished":"2022-10-31T11:51:50+00:00","dateModified":"2022-11-02T10:46:40+00:00","author":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/93565765cf85bc4be78b4d9ccbe294bb"},"description":"In this guide, we will get to know the steps to configure Apache Virtual Host on CentOS 7.","breadcrumb":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/how-to-configure-apache-virtual-hosts-on-centos7\/#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 CentOS7?"}]},{"@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\/17132","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=17132"}],"version-history":[{"count":9,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/17132\/revisions"}],"predecessor-version":[{"id":17171,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/17132\/revisions\/17171"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=17132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=17132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=17132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}