{"id":858,"date":"2019-07-24T17:33:32","date_gmt":"2019-07-24T17:33:32","guid":{"rendered":"http:\/\/dev.local\/?page_id=858"},"modified":"2020-02-16T16:10:43","modified_gmt":"2020-02-16T16:10:43","slug":"add-an-apaches-virtual-host","status":"publish","type":"page","link":"https:\/\/lamp.ciscoar.com\/?page_id=858","title":{"rendered":"Add an Apache&#8217;s Virtual Host"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/apache-pluma.png\"><img loading=\"lazy\" decoding=\"async\" width=\"243\" height=\"127\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/apache-pluma.png\" alt=\"\" class=\"wp-image-2589\"\/><\/a><\/figure><\/div>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">What is an Apache&#8217;s Virtual Host?<\/h2>\n\n\n\n<p>One of the main advantages of Apache is that it can be used either as and standalone server, that is, to store and serve only a single website or application or as a multiple sites server, that is, storing and serving several sites at the same time, each one of them is called a <strong>Virtual Host<\/strong>.<\/p>\n\n\n\n<p>These Virtual Hosts can have its own Domain Name, let&#8217;s say:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>example1.com<\/li><li>example2.com<\/li><li>&#8230;<\/li><li>exampleN.com<\/li><\/ul>\n\n\n\n<p>Or another possibility is to have them all as subdomains, let&#8217;s say:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>subdom1.example.com<\/li><li>subdom2.example.com<\/li><li>&#8230;<\/li><li>subdomN.example.com <\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Adding an Apache&#8217;s Virtual Host<\/h2>\n\n\n\n<p>Adding an Apache Virtual Host is a quite straightforward process if you can confirm the following prerequisites:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Your Apache web server is configured to run Virtual Hosts<\/li><li>You are able to add a new Domain\/Subdomain (DNS settings)<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Apache Virtual Hosts readiness<\/h2>\n\n\n\n<p>Is your Apache&#8217;s web server ready for the addition of a new Virtual Host? How can you tell if your Apache&#8217;s web server is or isn&#8217;t configured to serve multiple Virtual Hosts?<\/p>\n\n\n\n<p>The easy way to verify if your Apache&#8217;s web server is configured to serve Virtual Hosts is to check the folder <code class=\"\"><strong>\/etc\/httpd\/conf.d\/<\/strong><\/code> to see if you can find there one or more Virtual Host files (*.conf), see below image:<\/p>\n\n\n<p class=\"fonts-plugin-block \" style=\"font-family: calibri;font-weight: 700;font-size: 20px;color: #9b51e0\">\/etc\/httpd\/conf.d\/<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/08\/linux-directory-tree-apache-virtual-host-file-v6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"543\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/08\/linux-directory-tree-apache-virtual-host-file-v6.png\" alt=\"linux directory tree apache virtual host file\" class=\"wp-image-970\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/08\/linux-directory-tree-apache-virtual-host-file-v6.png 880w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/08\/linux-directory-tree-apache-virtual-host-file-v6-300x185.png 300w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/08\/linux-directory-tree-apache-virtual-host-file-v6-768x474.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Note<\/strong>: It is possible that along with the Virtual Hosts files you can also find the respective SSL files, on which the location for the SSL Certificate, Key file and Chain file are defined, we are going to cover the SSL configuration in another article.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example of a typical Virtual Host file<\/h2>\n\n\n\n<p>Just as an example, see below screenshot to have an idea of how they look like, they are just small text files containing the necessary settings to define each Virtual Host.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/06\/apache-virtual-host-sample.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"359\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/06\/apache-virtual-host-sample.jpg\" alt=\"virtual host file example\" class=\"wp-image-747\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/06\/apache-virtual-host-sample.jpg 598w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2019\/06\/apache-virtual-host-sample-300x180.jpg 300w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Download Virtual Host template<\/h2>\n\n\n\n<p>In case you need a Virtual Host template, feel free to download the following one:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"\/download\/subdomain-virtual-host-example.txt\">subdomain-virtual-host-example.txt<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s inside the .conf file?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">A record and C-Name<\/h3>\n\n\n\n<p>As you can see inside the &#8220;<strong>.conf<\/strong>&#8221; file, the parameter called <strong>ServerName<\/strong> is actually the site name, in DNS terms called  &#8220;Domain Name&#8221;  or just &#8220;Domain&#8221;, depending on each case this can be also one particular &#8220;subdomain&#8221;, this parameter in DNS terms is known as an &#8220;A&#8221; record.<\/p>\n\n\n\n<p>The <strong>ServerAlias<\/strong> parameter or simply &#8220;alias&#8221; is what in DNS terms is called CNAME, the most common and well known alias is the &#8220;www&#8221;, do not worry much about all of this, we are going to configure both parameters when covering the <a href=\"\/digital-ocean-domain-settings\/\">DNS part<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Virtual Host related folders<\/h3>\n\n\n\n<p>Two important folders are also defined inside each virtual host file, the main folder called &#8220;<strong>DocumentRoot<\/strong>&#8221; where all the website files will be located (html, javascript, css, php, images, etc).<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\/var\/www\/example.com\/public_html<\/strong><\/li><\/ul>\n\n\n\n<p> and the &#8220;<strong>Logging folder<\/strong>&#8221; where the respective site error log files will be saved.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>  <strong>\/var\/log\/httpd<\/strong><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Apache Virtual Hosts ready<\/h2>\n\n\n\n<p>If you can find the Virtual Host file and also its respective folder and log files, that means your Apache web server is serving virtual hosts and now you can move forward to add a new one, of course we are going to guide ourselves using an existing virtual host to do a sort of mirroring the configuration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where to go next?<\/h2>\n\n\n\n<p>The next step is to <a href=\"\/apache-virtual-host-file\">create a new Virtual Host file<\/a> (.conf)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is an Apache&#8217;s Virtual Host? One of the main advantages of Apache is that it can be used either as and standalone server, that is, to store and serve only a single website or application or as a multiple sites server, that is, storing and serving several sites at the same time, each one &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lamp.ciscoar.com\/?page_id=858\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Add an Apache&#8217;s Virtual Host&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-858","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=858"}],"version-history":[{"count":77,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/858\/revisions"}],"predecessor-version":[{"id":3529,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/858\/revisions\/3529"}],"wp:attachment":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}