<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>aBinaryMind &#187; apache</title>
	<atom:link href="http://www.abinarymind.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.abinarymind.com</link>
	<description>Some thoughts, some info, some rants</description>
	<lastBuildDate>Wed, 30 Jun 2010 15:36:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Automatic virtual host with Apache</title>
		<link>http://www.abinarymind.com/2009/10/automatic-virtual-host-with-apache/</link>
		<comments>http://www.abinarymind.com/2009/10/automatic-virtual-host-with-apache/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:35:02 +0000</pubDate>
		<dc:creator>lexhung</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[virtualhost]]></category>

		<guid isPermaLink="false">http://www.abinarymind.com/?p=95</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>When developing with CakePHP, we can setup Apache to automatically redirect a domain to a specific CakePHP application.</p>
<p>We can set computer&#8217;s aliases using <a href="http://en.wikipedia.org/wiki/Hosts_file">hosts file</a>. Apache will automatically map aliases to different DocumentRoot:</p>
<p><strong>app1.mybox.com</strong> -&gt; /var/www/cakephp/<strong>app1.mybox.com</strong>/webroot<br />
<strong>app2.somewhere.com</strong> -&gt; /var/www/cakephp/<strong>app2.somewhere.com</strong>/webroot</p>
<p><strong>Step 1:</strong> Enable the mod_vhost_alias:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ sudo a2enmod vhost_alias</div></div>
<p><strong>Step 2:</strong> Replace the DocumentRoot statement in <em>default</em> virtualhost configuration file with two lines:</p>
<div class="codecolorer-container apache default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">UseCanonicalName</span> &nbsp; &nbsp;<span style="color: #0000ff;">Off</span><br />
<span style="color: #00007f;">VirtualDocumentRoot</span> /var/www/cakephp/%0/webroot</div></div>
<p>(If you use a different virtualhost, make sure that you&#8217;re editing the right configuration file)</p>
<p><strong>Step 3:</strong> However, the mod_rewrite doesn&#8217;t play nice with mod_vhost_alias. We need to edit the .htaccess file in {APP}/webroot folder.</p>
<div class="codecolorer-container apache default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">RewriteBase</span> / &nbsp; <span style="color: #adadad; font-style: italic;"># &lt;&lt; Add this line</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-d</div></div>
<p><strong>Step 4:</strong> Restart Apache.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo service apache2 restart</div></div>
<p>Below is my default virtual host configuration for your reference:</p>
<div class="codecolorer-container apache default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">ServerAdmin</span> webmaster@localhost<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">UseCanonicalName</span> <span style="color: #0000ff;">Off</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">VirtualDocumentRoot</span> /var/www/cakephp/%0/webroot<br />
<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight:bold;">Directory</span> /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">FollowSymLinks</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span><br />
&nbsp; &nbsp; &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
<br />
&nbsp; &nbsp; <span style="color: #00007f;">ErrorLog</span> /var/log/apache2/error.log<br />
<br />
&nbsp; &nbsp; <span style="color: #adadad; font-style: italic;"># Possible values include: debug, info, notice, warn, error, crit,</span><br />
&nbsp; &nbsp; <span style="color: #adadad; font-style: italic;"># alert, emerg.</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">LogLevel</span> warn<br />
<br />
&nbsp; &nbsp; <span style="color: #00007f;">CustomLog</span> /var/log/apache2/access.log combined<br />
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.abinarymind.com/2009/10/automatic-virtual-host-with-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
