{"id":340,"date":"2009-10-05T11:52:09","date_gmt":"2009-10-05T16:52:09","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=340"},"modified":"2009-10-05T14:40:19","modified_gmt":"2009-10-05T19:40:19","slug":"setting-up-virtual-hosts-in-apache","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2009\/10\/setting-up-virtual-hosts-in-apache\/","title":{"rendered":"Setting Up Virtual Hosts In Apache"},"content":{"rendered":"<p>Setting Up Virtual Hosts In Apache, and also Editing The Host File On Windows.<\/p>\n<p>For this test, I have an Ubuntu 9.04 Server (LAMP) running Apache2.  I also have the testing machine of a Windows 7 Enterprise workstation using Firefox browser, notepad\/notepad2 for editing, and putty for ssh connections.<\/p>\n<p>Setting up a virtual host in Apache used to be a long and arduous task &#8211; now they&#8217;ve made it almost foolproof.  Before I start on the how-to, let&#8217;s look into why-we-should:<br \/>\nThere are a limited number of IPv4 IP addresses<br \/>\nWebsites generally do not use up all of the resources of a high-powered server<br \/>\nIt costs quite a bit more money to run a single website on a single server (if you&#8217;re hosting yourself there&#8217;s the power, internet, maintenance, and other problems to add up)<\/p>\n<p>Obviously there is more than one way to go about this, but this is how I did it on my setup:<\/p>\n<p>Log into your Linux server using putty or another SSH application<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/1_login.png\" alt=\"1_login\" title=\"1_login\" width=\"555\" height=\"360\" class=\"alignnone size-full wp-image-345\" srcset=\"https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/1_login.png 555w, https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/1_login-300x194.png 300w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><br \/>\nI&#8217;m using the root user &#8211; if you log as another user you may have to run &#8220;sudo command_here&#8221; commands.  So if one of your commands does not work, try with the prefix sudo.<br \/>\n<code>cd \/etc\/apache2\/sites-available<\/code><br \/>\n<code>nano default<\/code><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/2_apache_sites_avail.png\" alt=\"2_apache_sites_avail\" title=\"2_apache_sites_avail\" width=\"555\" height=\"360\" class=\"alignnone size-full wp-image-346\" srcset=\"https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/2_apache_sites_avail.png 555w, https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/2_apache_sites_avail-300x194.png 300w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/p>\n<p>Page down to the end of this file.  Everything that is in there should have been installed by default &#8211; and we only want to add to the sites and not edit.<br \/>\nAdd the following:<\/p>\n<pre>NameVirtualHost name_of_your_host\r\n\r\n&lt;VirtualHost IP_of_your_webserver&gt;\r\n    DocumentRoot \/path\/to\/your\/files\r\n    ServerName domain.tld\r\n    ServerAlias *.domain.tld\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/3_apache_sa_edited.png\" alt=\"3_apache_sa_edited\" title=\"3_apache_sa_edited\" width=\"555\" height=\"360\" class=\"alignnone size-full wp-image-347\" srcset=\"https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/3_apache_sa_edited.png 555w, https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/3_apache_sa_edited-300x194.png 300w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/p>\n<p>Control X and select save your file.  After you save, you&#8217;ll have to reset\/reload apache so it can re-read the configuration files:<br \/>\n<code>apache2ctl restart<\/code><\/p>\n<p>Now to test on your Windows machine we need to edit your hosts file and add the hostname and IP address of your test server.<\/p>\n<blockquote><p>Start &gt; run (or Windows Key + R)<br \/>\nc:\\windows\\system32\\drivers\\etc<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/4_host_file_location.png\" alt=\"4_host_file_location\" title=\"4_host_file_location\" width=\"427\" height=\"235\" class=\"alignnone size-full wp-image-348\" srcset=\"https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/4_host_file_location.png 427w, https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/4_host_file_location-300x165.png 300w\" sizes=\"auto, (max-width: 427px) 100vw, 427px\" \/><br \/>\nEdit the hosts file using your favorite text editor (notepad or notepad2 for me)<br \/>\nAt the bottom of the file you will need to make the changes:<br \/>\n<code>IP_address DNS_Name<\/code><\/p><\/blockquote>\n<p>Notice that you can have as many DNS names for each IP address as you want.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/5_host_file_edited.png\" alt=\"5_host_file_edited\" title=\"5_host_file_edited\" width=\"642\" height=\"491\" class=\"alignnone size-full wp-image-349\" srcset=\"https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/5_host_file_edited.png 642w, https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2009\/10\/5_host_file_edited-300x229.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/p>\n<p>Now, open up your favorite browser (chrome or firefox) and navigate to the name you setup.  In my case, I go to http:\/\/test.com.  Since it loaded my test site which was different from my generic http:\/\/10.4.0.68 site, I know it&#8217;s working.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting Up Virtual Hosts In Apache, and also Editing The Host File On Windows. For this test, I have an Ubuntu 9.04 Server (LAMP) running Apache2. I also have the testing machine of a Windows 7 Enterprise workstation using Firefox browser, notepad\/notepad2 for editing, and putty for ssh connections. Setting up a virtual host in &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2009\/10\/setting-up-virtual-hosts-in-apache\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Setting Up Virtual Hosts In Apache<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,8],"tags":[],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-linux","category-microsoft"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":6,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":371,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/340\/revisions\/371"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}