{"id":3276,"date":"2017-09-07T15:36:14","date_gmt":"2017-09-07T19:36:14","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=3276"},"modified":"2017-09-25T13:08:38","modified_gmt":"2017-09-25T17:08:38","slug":"apache-virtual-hosts-c7","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/","title":{"rendered":"How To Set Up Apache Virtual Hosts on CentOS 7"},"content":{"rendered":"<div align=\"center\"><img decoding=\"async\" src=\"https:\/\/projects.apache.org\/images\/asf_logo.png\" alt=\"The Apache Foundation\" style=\"width: 50%; height: 50%;\"\/><\/div>\n<h1>How To Set Up Apache Virtual Hosts on CentOS 7<\/h1>\n<p>An <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\/\" rel=\"nofollow\">Apache Virtual Hosts<\/a> allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to host multiple sites or domains that are cleanly separated from each other. There is no limit to the number of virtual hosts for the Apache server however you must keep your hardware limitations in mind.<\/p>\n<h2>Getting Started<\/h2>\n<p>To complete this walkthrough successfully the following are required:<br \/>\n\u2022 A node (<a href=\"https:\/\/www.globo.tech\/dedicated-server-hosting\" rel=\"nofollow\">Dedicated<\/a> or <a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" rel=\"nofollow\">Cloud Server<\/a>)running CentOS 7<\/a><br \/>\n\u2022 All commands must be entered as root<br \/>\n\u2022 A complete <a href=\"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/\">LAMP implementation<\/a><\/p>\n<h2>Tutorial &#8211; Apache Virtual Hosts<\/h2>\n<p>For the purpose of this article, we will set up a virtual host for globo.tech on our instance of Apache.<\/p>\n<p>We will start with disabling SELinux. This will make testing the setup easier and can be re-enabled later with the proper context to handle the new virtual host.<br \/>\n<code>setenforce 0<br \/>\nsed -i 's\/enforcing\/disabled\/' \/etc\/sysconfig\/selinux<br \/>\nsed -i 's\/enforcing\/disabled\/' \/etc\/selinux\/config<\/code><\/p>\n<p>Each virtual host must have its own top-level directory under \/var\/www. Use the mkdir command to create the directory for globo.tech and the public_html subdirectory.<br \/>\n<code>mkdir -p \/var\/www\/globo.tech\/public_html\/<\/code><\/p>\n<p>Since this directory is owned by the root user, we will need to specifically grant access rights to Apache.<br \/>\n<code>chown -R apache. \/var\/www\/<br \/>\nchmod -R 755 \/var\/www\/globo.tech\/<\/code><\/p>\n<p>Apache will also need to know where to look for additional *.conf files as each virtual host will have one. Open the main configuration file for Apache at \/etc\/httpd\/httpd.conf and add this line at the end.<br \/>\n<code>nano \/etc\/httpd\/conf\/httpd.conf<br \/>\nIncludeOptional sites-enabled\/*.conf<\/code><\/p>\n<p>Now we will create two additional folders enable virtual hosts on the system. One directory will hold all the virtual host files while the other will hold symbolic links for each virtual host published by Apache.<br \/>\n<code>mkdir \/etc\/httpd\/sites-available<br \/>\nmkdir \/etc\/httpd\/sites-enabled<\/code><\/p>\n<p>Once that is done we can create the *.conf file for the virtual host. In this case, we will create the globo.tech.conf file in \/etc\/httpd\/site-available directory. Remember that we&#8217;ve already instructed Apache to look for additional config files at this location.<br \/>\n<code>cd \/etc\/httpd\/sites-available\/<br \/>\nnano globo.tech.conf<\/code><br \/>\n<code class=\"gris\">&lt;VirtualHost *:80&gt;<br \/>\n    ServerAdmin webmaster@globo.tech<br \/>\n    ServerName www.globo.tech<br \/>\n    ServerAlias globo.tech<br \/>\n    DocumentRoot \/var\/www\/globo.tech\/public_html<br \/>\n    ErrorLog \/var\/www\/globo.tech\/error.log<br \/>\n    CustomLog \/var\/www\/globo.tech\/access.log combined<br \/>\n&lt;\/Virtualhost&gt;<\/code><\/p>\n<p>Then we will need to create the symbolic link for globo.tech in the \/etc\/httpd\/sites-enabled directory.<br \/>\n<code>ln -s \/etc\/httpd\/sites-available\/globo.tech.conf \/etc\/httpd\/sites-enabled\/globo.tech.conf<\/code><\/p>\n<p>After all the above steps have been completed, it is now time to restart Apache. Use this command in order for the server to publish the globo.tech virtual host.<br \/>\n<code>systemctl restart httpd.service<\/code><\/p>\n<p>If the instructions have been followed completely, you can place your website files in the root document directory of globo.tech at \/var\/www\/globo.tech\/public_html. All you need to do is point your browser to the domain name at the server IP to see your virtual host.<\/p>\n<h2>Conclusion<\/h2>\n<p>We hope you have enjoyed learning about setting up an Apache virtual host on CentOS 7. You can always experiment further by adding more sites to your server. If you have found this article useful, please consider sharing it.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How To Set Up Apache Virtual Hosts on CentOS 7 An Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to host multiple sites or domains that are cleanly separated from each other. There is no limit<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-3276","post","type-post","status-publish","format-standard","hentry","category-web-hosting","operating_system-centos-7"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Set Up Apache Virtual Hosts on CentOS 7 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to ...\" \/>\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.globo.tech\/learning-center\/apache-virtual-hosts-c7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Set Up Apache Virtual Hosts on CentOS 7 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-07T19:36:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-09-25T17:08:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/projects.apache.org\/images\/asf_logo.png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/\",\"name\":\"How To Set Up Apache Virtual Hosts on CentOS 7 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/projects.apache.org\/images\/asf_logo.png\",\"datePublished\":\"2017-09-07T19:36:14+00:00\",\"dateModified\":\"2017-09-25T17:08:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to ...\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#primaryimage\",\"url\":\"https:\/\/projects.apache.org\/images\/asf_logo.png\",\"contentUrl\":\"https:\/\/projects.apache.org\/images\/asf_logo.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Set Up Apache Virtual Hosts on CentOS 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Set Up Apache Virtual Hosts on CentOS 7 - Globo.Tech","description":"Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to ...","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.globo.tech\/learning-center\/apache-virtual-hosts-c7\/","og_locale":"en_US","og_type":"article","og_title":"How To Set Up Apache Virtual Hosts on CentOS 7 - Globo.Tech","og_description":"Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to ...","og_url":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/","og_site_name":"Globo.Tech","article_published_time":"2017-09-07T19:36:14+00:00","article_modified_time":"2017-09-25T17:08:38+00:00","og_image":[{"url":"https:\/\/projects.apache.org\/images\/asf_logo.png","type":"","width":"","height":""}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/","url":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/","name":"How To Set Up Apache Virtual Hosts on CentOS 7 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#primaryimage"},"image":{"@id":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#primaryimage"},"thumbnailUrl":"https:\/\/projects.apache.org\/images\/asf_logo.png","datePublished":"2017-09-07T19:36:14+00:00","dateModified":"2017-09-25T17:08:38+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to ...","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#primaryimage","url":"https:\/\/projects.apache.org\/images\/asf_logo.png","contentUrl":"https:\/\/projects.apache.org\/images\/asf_logo.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/apache-virtual-hosts-c7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How To Set Up Apache Virtual Hosts on CentOS 7"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=3276"}],"version-history":[{"count":18,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3276\/revisions"}],"predecessor-version":[{"id":3456,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3276\/revisions\/3456"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=3276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=3276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=3276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}