<?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>Stei{nerd}.com &#187; Scripts</title>
	<atom:link href="http://steinerd.com/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://steinerd.com</link>
	<description>Development, Ideas &#38; Thoughts of Anthony Steiner</description>
	<lastBuildDate>Mon, 21 Jun 2010 00:09:42 +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>Apache 2.x userdir_mod</title>
		<link>http://steinerd.com/scripts/apache2__userdir_mod/</link>
		<comments>http://steinerd.com/scripts/apache2__userdir_mod/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 03:17:23 +0000</pubDate>
		<dc:creator>steiner</dc:creator>
				<category><![CDATA[Random Scripts/Ideas]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://steinerd.com/?p=99</guid>
		<description><![CDATA[Well, Titan Network has been using a method to fix/update/create sites within the same LAMP environment as the server the live sites are on&#8230; So Dan Da Cunha implemented a brilliant idea using apache&#8217;s symbolic links (symlinks). We&#8217;d log into the server without respective user-names and passwords, and once in we&#8217;d simply go to our [...]]]></description>
			<content:encoded><![CDATA[<p>Well, Titan Network has been using a method to fix/update/create sites within the same <abbr title="Linux, Apache, MySQL, PHP/Perl">LAMP</abbr> environment as the server the live sites are on&#8230; So Dan Da Cunha implemented a brilliant idea using apache&#8217;s symbolic links (symlinks).</p>
<p>We&#8217;d log into the server without respective user-names and passwords, and once in we&#8217;d simply go to our user-named subdomain folder and do the following.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p99code3'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p993"><td class="code" id="p99code3"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">svn</span>
$ <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> project_name active</pre></td></tr></table></div>

<p>However, the back-end of it was a bit of headache. First we had to create a CNAME in our DNS records for <em><strong>each</strong> </em>developer, then create vhosts for each individual user-based sub-domain.</p>
<p>That wasn&#8217;t as big a deal as I&#8217;m making it out to be&#8230; but I&#8217;m a fan of SIMPLER, lol. Plus the ultimate con to this setup is that you only get to point ONE folder to your active project. So if you want to have someone check out your progress and move onto another project in the interim&#8230; you couldn&#8217;t.</p>
<p>So I had an idea to utilize the userdir_mod Apache2 uses; Create <strong><em>one </em><em> </em></strong>CNAME in the DNS.</p>
<p><strong>CNAME:</strong> *<br />
<strong>Alias To:</strong> your domain</p>
<p>That&#8217;s called a <em>wildcard</em> CNAME. It lets us use pretty much anything for a sub-domain without having to create multiple records for each one. And with a few tweaks to the default vhost record and the userdir_mod, we were running each project folder we had from our <code>/home/usename/public_html</code> directory in a 2 part sub-domain.</p>
<p>http://&lt;project_name&gt;.&lt;username&gt;.domain.com</p>
<p>Yea, I know&#8230; you&#8217;re asking why don&#8217;t we just edit them from the folder root&#8230; well because all the sites we make are for domain root&#8230; and that would mess up a lot of CSS and image linking.</p>
<hr />Steps to do this on your server. (Assuming you&#8217;re using the Apache packed with PHP and using Vhosts)</p>
<p><span style="text-decoration: underline;"><strong>Step 1<br />
</strong></span>Open <code>/etc/apache2/sites-available/default</code> in your favorite text editor.</p>
<p><span style="text-decoration: underline;"><strong>Step 2<br />
</strong></span>Sadly, now that we have a wildcard CNAME, supercalifragilisticexpialidocious.domain.com will bring up your site&#8217;s default vhost location&#8217;s directory listing (given you have autoindex_mod enabled)</p>
<p>TAKE NOTE, whether your VirtualHost file is headed like this &lt;VirtualHost *:80&gt; or something else, because step 3 is going to need the same structure.</p>
<p>Either put a faux index.php file in the &#8220;DocumentRoot&#8221; location<br />
&#8211; OR &#8211;<br />
Edit the first &lt;Directory /&gt; node to have <code>Options Indexes</code> changed to <code>Options -Indexes</code> so the directory won&#8217;t list and it will just reply with a HTTP/1 403 error.<br />
&#8211; OR &#8211;<br />
Put DirectoryIndex /path/to/file/name.php in your first line under the first &lt;Directory /&gt; node and point it to a php script that forwards them off to the main site or something, use your imagination!</p>
<p><span style="text-decoration: underline;"><strong>Step 3<br />
</strong></span>Open <code>/etc/apache2/mods-available/userdir.conf </code>in your favorite text editor.<br />
Slap a # in front of each line in the orignal text to comment it out, and copy and paste the snippet below (make your edits post-paste).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p99code4'); return false;">View Code</a> APACHE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p994"><td class="code" id="p99code4"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
	&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_userdir.c&gt;
			<span style="color: #00007f;">UseCanonicalName</span> <span style="color: #0000ff;">Off</span>
			<span style="color: #00007f;">ServerName</span>	  *.domain.com
			<span style="color: #00007f;">ServerAlias</span>	 *.*.domain.com
			<span style="color: #00007f;">UserDir</span> /home/*/public_html
			<span style="color: #00007f;">UserDir</span> disabled root
			<span style="color: #00007f;">VirtualDocumentRoot</span> /home/%2/public_html/%1
			&lt;<span style="color: #000000; font-weight:bold;">Directory</span> /&gt;
					<span style="color: #00007f;">Options</span> +<span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span>
					<span style="color: #00007f;">DirectoryIndex</span> index.php index.html index.htm
					<span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
			&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
			<span style="color: #00007f;">ServerAdmin</span> support@domain.com
	&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></td></tr></table></div>

<p>Obviously you can change some things around to your likings.</p>
<p>%1 is the first segment of your URL/URI<br />
%2 is the second segment of your URL/URI</p>
<p>The reason we don&#8217;t put the user-name first in the URL is because if there is an already existing subdomain with the same name is your home directory&#8217;s public_html sub-directory, they will conflict and return a server error.</p>
<p>All underlying info can be found at <a title="Apache 2.0 mod_vhost_alias" href="http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html" target="_blank">http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html</a>.</p>
<p>From here you simple enable your userdir mod (if you haven&#8217;t already) and give it a test.</p>
<p>NOTE: DNS records take about an hour to propagate, so if it doesn&#8217;t work right away to be surprised.</p>
]]></content:encoded>
			<wfw:commentRss>http://steinerd.com/scripts/apache2__userdir_mod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
