{"id":493,"date":"2009-01-16T11:37:07","date_gmt":"2009-01-16T19:37:07","guid":{"rendered":"http:\/\/www.laurenwood.org\/anyway\/?p=493"},"modified":"2009-02-09T10:01:19","modified_gmt":"2009-02-09T18:01:19","slug":"virtual-hosts","status":"publish","type":"post","link":"https:\/\/www.laurenwood.org\/anyway\/2009\/01\/virtual-hosts\/","title":{"rendered":"Apache Virtual Hosts"},"content":{"rendered":"<p>Notes on installing Apache\u2019s vir\u00adtu\u00adal hosts on <a href=\"http:\/\/opensolaris.org\/os\/\">OpenSol\u00adar\u00adis<\/a> 2008.11; part of a series that star\u00adted with <a href=\"http:\/\/www.laurenwood.org\/anyway\/2009\/01\/installing-opensolaris\/\">Installing OpenSol\u00adar\u00adis<\/a>.<\/p>\n<p>On Debi\u00adan, you have to set up vir\u00adtu\u00adal hosts using sep\u00adar\u00adate files, called <em>sites-enabled<\/em> and <em>sites-avail\u00adable<\/em>, part of the Debi\u00adan Way Of Doing Things, which is not doc\u00adu\u00admented on the Apache site. (I\u2019ve <a href=\"http:\/\/www.laurenwood.org\/anyway\/2006\/01\/woody-to-sarge\/\">writ\u00adten about this before<\/a>; the link I refer to there is no longer avail\u00adable, so <a href=\"http:\/\/www.debianhelp.co.uk\/apacheupgrade.htm\">try this one<\/a> if you\u2019re on a Debi\u00adan or Ubuntu plat\u00adform.) For\u00adtu\u00adnately, OpenSol\u00adar\u00adis seems to use the stand\u00adard Apache meth\u00adods, so named vir\u00adtu\u00adal hosts can be set up using the doc\u00adu\u00adment\u00ada\u00adtion at <a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/vhosts\/name-based.html\">Name-based Vir\u00adtu\u00adal Host Sup\u00adport<\/a> (the meth\u00adod you choose when you want to run mul\u00adtiple web sites from one <span class=\"caps\">IP<\/span> address). It\u2019s easy to find the <code>httpd.conf<\/code> file, it\u2019s in the Web Stack Options applic\u00ada\u00adtion, under <em>Advanced Con\u00adfig\u00adur\u00ada\u00adtion<\/em> on the <code>Apache2<\/code> tab (and even labelled \u201c<em>edit httpd.conf<\/em>\u201d). <\/p>\n<p>I set up a vir\u00adtu\u00adal host for each web site on the devel\u00adop\u00adment machine. This is a little more com\u00adplic\u00adated than it is if you\u2019re start\u00ading from scratch with a new site, since I want to be able to set up all the soft\u00adware and sys\u00adtems on each web site on a test basis, before switch\u00ading the old serv\u00ader off and the new one on. In the mean\u00adtime of course, the old serv\u00ader is still serving those web\u00adsites with the same URLs. So I needed a sys\u00adtem that allows the com\u00adputer I\u2019m devel\u00adop\u00ading on to see the new sites reached from those URLs, while the rest of the world sees the old&nbsp;sites.<\/p>\n<p>The way to do this is to edit the  <em>hosts<\/em> file on the devel\u00adop\u00adment machine. In a ter\u00admin\u00adal win\u00addow, type <code>pfexec vim \/etc\/hosts<\/code>. After the bot\u00adtom line, which should look some\u00adthing like <code>127.0.0.1  <em>machinename<\/em>.local localhost loghost<\/code>, add the line(s) <code>127.0.0.1 <em>websitename<\/em><\/code>. You don\u2019t even need to reboot or restart the Apache serv\u00ader, which is nice. If it does\u00adn\u2019t work (you don\u2019t see what you expect in your browser), take a look at your <em>\/etc\/nsswitch.conf<\/em> file and make sure that the <code>hosts<\/code> line has the <code>files<\/code> dir\u00adect\u00adive before the <code>dns<\/code> dir\u00adect\u00adive, oth\u00ader\u00adwise the sys\u00adtem will ask the <span class=\"caps\">DNS<\/span> serv\u00ader (which will return the site the rest of the world sees) before ask\u00ading the <em>hosts<\/em> file on your sys\u00adtem. One way to check which <span class=\"caps\">IP<\/span> address you\u2019re look\u00ading at to make sure you\u2019re look\u00ading at your test sys\u00adtem, not the out\u00adside one on the net, is to use <code>getent hosts <em>websitename<\/em><\/code>. This should tell you the <span class=\"caps\">IP<\/span> address is 127.0.0.1. The com\u00admon altern\u00adat\u00adive com\u00admand, <code>host <em>websitename<\/em><\/code>, asks the <span class=\"caps\">DNS<\/span> serv\u00ader and thus will tell you what the out\u00adside world&nbsp;sees.<\/p>\n<p>Debug\u00adging the <em>httpd.conf<\/em> file is the next step, to make sure you have those vir\u00adtu\u00adal hosts set up cor\u00adrectly. In the end, I just&nbsp;added&nbsp;<\/p>\n<pre><code>NameVirtualHost *:80\n\n&lt;VirtualHost *:80&gt;\n  ServerName <em>domainname<\/em>\n  ServerAlias <em>domainname<\/em> www.<em>domainname<\/em>\n  DocumentRoot \"\/var\/apache2\/2.2\/htdocs\/<em>domain<\/em>\"\n  CustomLog \"\/var\/apache2\/2.2\/logs\/access_log\" combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<p>to the end of the exist\u00ading <em>httpd.conf<\/em> file.&nbsp;<\/p>\n<p>Update: I also had to&nbsp;add<\/p>\n<pre><code>  &lt;Directory \/var\/apache2\/2.2\/htdocs\/<em>domain<\/em>&gt;\n         Options Indexes MultiViews FollowSymLinks\n          AllowOverride FileInfo\n          Order allow,deny\n          Allow from all\n&lt;\/Directory&gt;<\/code><\/pre>\n<p>to the vir\u00adtu\u00adal host dir\u00adect\u00adive (just above the cus\u00adtom log line) to make Word\u00adPress\u2019s pret\u00adti\u00ader permalinks work.<\/p>\n<p>The one thing OpenSol\u00adar\u00adis does that is dif\u00adfer\u00adent to the Apache doc\u00adu\u00adment\u00ada\u00adtion is put\u00adting things some\u00adwhere dif\u00adfer\u00adent, so instead of using <code>\/usr\/local\/apache2\/bin\/httpd -S<\/code> to debug the vir\u00adtu\u00adal host con\u00adfig\u00adur\u00ada\u00adtion, you use <code>\/usr\/apache2\/2.2\/bin\/httpd -S<\/code>. I learned the hard way that if you want to use a default vir\u00adtu\u00adal host, you have to define a <code>ServerName<\/code> for&nbsp;it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notes on installing Apache\u2019s vir\u00adtu\u00adal hosts on OpenSol\u00adar\u00adis 2008.11; part of a series that star\u00adted with Installing OpenSol\u00adar\u00adis. On Debi\u00adan, you have to set up vir\u00adtu\u00adal hosts using sep\u00adar\u00adate files, called sites-enabled and sites-avail\u00ad\u00adable, part of the Debi\u00adan Way Of Doing Things, which is not doc\u00adu\u00admented on the Apache site. (I\u2019ve writ\u00adten about this before; \u2026 <a href=\"https:\/\/www.laurenwood.org\/anyway\/2009\/01\/virtual-hosts\/\" class=\"more-link\">Con\u00adtin\u00adue read\u00ading<span class=\"screen-reader-text\"> \u201cApache Vir\u00adtu\u00adal&nbsp;Hosts\u201d<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wp_typography_post_enhancements_disabled":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":""},"categories":[6],"tags":[68,20],"class_list":["post-493","post","type-post","status-publish","format-standard","hentry","category-technology","tag-apache","tag-opensolaris"],"_links":{"self":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts\/493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/comments?post=493"}],"version-history":[{"count":22,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts\/493\/revisions"}],"predecessor-version":[{"id":585,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts\/493\/revisions\/585"}],"wp:attachment":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/media?parent=493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/categories?post=493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/tags?post=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}