{"id":3264,"date":"2018-01-04T14:43:48","date_gmt":"2018-01-04T19:43:48","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=3264"},"modified":"2018-01-04T14:43:48","modified_gmt":"2018-01-04T19:43:48","slug":"configure-apache-virtual-hosts-ubuntu16","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/","title":{"rendered":"How To Configure Apache Virtual Hosts on Ubuntu 16"},"content":{"rendered":"<h1>How To Configure Apache Virtual Hosts on Ubuntu 16<\/h1>\n<div class=\"row\">\n<div class=\"col-lg-8\">\n<p>Virtual hosting is the technique of hosting multiple websites on one server. Virtual hosting enables efficient utilization of computing resources because the multiple websites share the computing resources of the host server. Apache is one of the most web servers in the world, and it provides a mechanism for enabling virtual hosting on a web server. Virtual hosting works by creating a directory for each domain\/website and then redirecting visitors of a domain to that site\u2019s specific directory. The whole process is handled transparently by <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\/\" rel=\"nofollow\">Apache<\/a>, and the user is not aware that the server is hosting other websites. Apache virtual hosting is very scalable and can be expanded to handle a large number of sites.<\/p>\n<\/div>\n<div class=\"col-lg-4\">\n<img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"130\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.png\" alt=\"\" class=\"alignright size-medium wp-image-3725\" \/>\n<\/div>\n<\/div>\n<p><strong>Getting started<\/strong><br \/>\nTo complete this walkthrough successfully the following are required:<br \/>\n\u2022 A node (<strong><a href=\"https:\/\/www.globo.tech\/dedicated-server-hosting\">Dedicated<\/a><\/strong> or <strong><a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\">Cloud Server<\/a><\/strong>) running Ubuntu 16<br \/>\n\u2022 All commands must be entered as root<br \/>\n\u2022 <a href=\"https:\/\/www.globo.tech\/learning-center\/how-to-setup-a-basic-lamp-linux-apache-mysql-and-php-on-ubuntu\/\">Apache web server<\/a> installed<\/p>\n<p><strong>Tutorial<\/strong><br \/>\nThis guide demonstrates how to implement virtual hosting for two domains, www.globo.tech and support.globo.tech, on a single server. The two domains can be substituted for any domain that you may use.<\/p>\n<p>First, create the directories for each website in the \/var\/www directory using the following commands:<br \/>\n<code>sudo mkdir -p \/var\/www\/www.globo.tech<br \/>\nsudo mkdir -p \/var\/www\/support.globo.tech<br \/>\nNext change the ownership of the directories so that the regular user can modify them:<br \/>\nsudo chown -R $USER:$USER \/var\/www\/www.globo.tech<br \/>\nsudo chown -R $USER:$USER \/var\/www\/support.globo.tech<\/code><\/p>\n<p>Next change the permissions for the directories so that visitors to the site can have read access to the web pages:<br \/>\n<code>sudo chmod -R 777 \/var\/www\/www.globo.tech<br \/>\nsudo chmod -R 777 \/var\/www\/support.globo.tech<\/code><\/p>\n<p>The next step is creating a virtual host file for each website; this is accomplished by copying the default virtual host file and then editing it appropriately. Use the following commands to copy the default host file:<\/p>\n<p><code>sudo cp \/etc\/apache2\/sites-available\/000-default.conf \/etc\/apache2\/sites-available\/www.globo.tech.conf<br \/>\nsudo cp \/etc\/apache2\/sites-available\/000-default.conf \/etc\/apache2\/sites-available\/support.globo.tech.conf<\/code><\/p>\n<p>The virtual host files have to be modified so that they can direct requests appropriately. Open the virtual host file for the www.globo.tech site using an editor of your choice. In this example nano has been used:<\/p>\n<p><code>sudo nano \/etc\/apache2\/sites-available\/www.globo.tech.conf<\/code><\/p>\n<p>Subsequently, add a directive for the ServerName, this is the domain for the website:<\/p>\n<p><code class=\"gris\">ServerName www.globo.tech<\/code><\/p>\n<p>Next, modify the DocumentRoot directive so that it matches the directory that you have created for the website<\/p>\n<p><code class=\"gris\">DocumentRoot \/var\/www\/www.global.tech<\/code><\/p>\n<p>If the changes have been implemented correctly the virtual host file will look this:<br \/>\n<code class=\"gris\">&lt;Virtualhost&gt;<br \/>\nServerAdmin webmaster@localhost<br \/>\nServerName www.global.tech<br \/>\nDocumentRoot \/var\/www\/www.global.tech<br \/>\nErrorLog ${APACHE_LOG_DIR}\/error.log<br \/>\nCustomLog ${APACHE_LOG_DIR}\/access.log combined<br \/>\n&lt;\/Virtualhost&gt;<\/code><\/p>\n<p>The same changes should be made for the support.global.tech website. Open the virtual host file using the following command:<br \/>\n<code>sudo nano \/etc\/apache2\/sites-available\/support.globo.tech.conf<\/code><\/p>\n<p>Alter the file so that it matches the following:<br \/>\n<code class=\"gris\">&lt;Virtualhost&gt;<br \/>\nServerAdmin webmaster@localhost<br \/>\nServerName support.global.tech<br \/>\nDocumentRoot \/var\/www\/support.global.tech<br \/>\nErrorLog ${APACHE_LOG_DIR}\/error.log<br \/>\nCustomLog ${APACHE_LOG_DIR}\/access.log combined<br \/>\n&lt;\/Virtualhost&gt;<\/code><\/p>\n<p>The final step is for enabling the new virtual hosts and reloading the web server. Apache provides the a2ensite tool for enabling sites. Use the following commands to enable the two sites:<br \/>\n<code>sudo a2ensite www.global.tech.conf<br \/>\nsudo a2ensite support.global.tech.conf<\/code><\/p>\n<p>Finally, reload apache using the following command:<br \/>\n<code>sudo systemctl restart apache2<\/code><\/p>\n<p><strong>Conclusion<\/strong><br \/>\nYou have now setup virtual hosting, and you can use your single server to serve two websites. You can experiment further by adding more sites to your server. If this walkthrough has assisted you, do not hesitate to share with other people.<\/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 Configure Apache Virtual Hosts on Ubuntu 16 Virtual hosting is the technique of hosting multiple websites on one server. Virtual hosting enables efficient utilization of computing resources because the multiple websites share the computing resources of the host server. Apache is one of the most web servers in the world, and it provides<!-- 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-3264","post","type-post","status-publish","format-standard","hentry","category-web-hosting","operating_system-ubuntu-16-04"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Configure Apache Virtual Hosts on Ubuntu 16 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"Virtual hosting is the technique of hosting multiple websites on one server. This tutorial will show you how to configure Apache Virtual Hosts on Ubuntu 16.\" \/>\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\/configure-apache-virtual-hosts-ubuntu16\/\" \/>\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 16 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"Virtual hosting is the technique of hosting multiple websites on one server. This tutorial will show you how to configure Apache Virtual Hosts on Ubuntu 16.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-04T19:43:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.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\/configure-apache-virtual-hosts-ubuntu16\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/\",\"name\":\"How To Configure Apache Virtual Hosts on Ubuntu 16 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.png\",\"datePublished\":\"2018-01-04T19:43:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"Virtual hosting is the technique of hosting multiple websites on one server. This tutorial will show you how to configure Apache Virtual Hosts on Ubuntu 16.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#primaryimage\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.png\",\"contentUrl\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.png\",\"width\":300,\"height\":130},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Configure Apache Virtual Hosts on Ubuntu 16\"}]},{\"@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 Configure Apache Virtual Hosts on Ubuntu 16 - Globo.Tech","description":"Virtual hosting is the technique of hosting multiple websites on one server. This tutorial will show you how to configure Apache Virtual Hosts on Ubuntu 16.","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\/configure-apache-virtual-hosts-ubuntu16\/","og_locale":"en_US","og_type":"article","og_title":"How To Configure Apache Virtual Hosts on Ubuntu 16 - Globo.Tech","og_description":"Virtual hosting is the technique of hosting multiple websites on one server. This tutorial will show you how to configure Apache Virtual Hosts on Ubuntu 16.","og_url":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/","og_site_name":"Globo.Tech","article_published_time":"2018-01-04T19:43:48+00:00","og_image":[{"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.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\/configure-apache-virtual-hosts-ubuntu16\/","url":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/","name":"How To Configure Apache Virtual Hosts on Ubuntu 16 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#primaryimage"},"image":{"@id":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#primaryimage"},"thumbnailUrl":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.png","datePublished":"2018-01-04T19:43:48+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"Virtual hosting is the technique of hosting multiple websites on one server. This tutorial will show you how to configure Apache Virtual Hosts on Ubuntu 16.","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#primaryimage","url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.png","contentUrl":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2017\/11\/Virtual-Hosts-1.png","width":300,"height":130},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/configure-apache-virtual-hosts-ubuntu16\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How To Configure Apache Virtual Hosts on Ubuntu 16"}]},{"@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\/3264","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=3264"}],"version-history":[{"count":17,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3264\/revisions"}],"predecessor-version":[{"id":4028,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3264\/revisions\/4028"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=3264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=3264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=3264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}