<?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>Jaysen Marais &#187; rails</title>
	<atom:link href="http://www.jaysenmarais.com/blog/tag/rails/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jaysenmarais.com/blog</link>
	<description>Making it happen, bit by bit</description>
	<lastBuildDate>Tue, 10 Jan 2012 06:50:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Deploy a rails app to bluehost without SSH</title>
		<link>http://www.jaysenmarais.com/blog/20100410/deploy_a_rails_app_to_bluehost_without_ssh</link>
		<comments>http://www.jaysenmarais.com/blog/20100410/deploy_a_rails_app_to_bluehost_without_ssh#comments</comments>
		<pubDate>Sat, 10 Apr 2010 10:19:33 +0000</pubDate>
		<dc:creator>jaysen</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[bluehost]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[RoR]]></category>
		<category><![CDATA[shared hosting]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://www.jaysenmarais.com/blog/?p=227</guid>
		<description><![CDATA[I&#8217;ve been doing a little free-lance web development again lately. It&#8217;s been a while and the landscape&#8217;s changed in the 2 or 3 years since I was last freelancing. Specifically the &#8216;minimum requirements&#8217; for a public facing site and the quality of the &#8216;cheap&#8217; generic hosts have both increased (for the better). In light of [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
	code { font-size: 12px; font-family: Bitstream Vera Sans Mono, Monaco, monospace; }
	.snippet { text-align: left; font-size: 12px; display: block; border: solid 1px #eee; background: #f8f8f8; padding: 10px; font-family: Bitstream Vera Sans Mono, Monaco, monospace; margin-bottom: 1em; }
   		.snippet .comment { font-style: italic; color: #AAA; }
		.snippet .keyword { font-weight: bold; }
		.snippet .string { color: #0031ff; }
		.snippet .entity { text-decoration: underline; }
		.snippet .storage { color: #888; }
		.snippet .support { color: #006803; }
		.snippet .constant, .variable { color: #F0F; }
</style>
<p><img src="http://www.jaysenmarais.com/blog_media/201004/rails_on_bluehost.png" width="230" height="121" alt="rails on bluehost" style="float: right; margin-left: 15px;" /></p>
<p>I&#8217;ve been doing a little free-lance web development again lately. It&#8217;s been a while and the landscape&#8217;s changed in the 2 or 3 years since I was last freelancing. Specifically the &#8216;minimum requirements&#8217; for a public facing site and the quality of the &#8216;cheap&#8217; generic hosts have both increased (for the better). In light of these two factors I&#8217;ve been having a go at making some basic &#8216;web-presence&#8217; sites using <a href="http://rubyonrails.org/">ruby on rails</a>.</p>
<p>Learning enough rails to make a simple site was easy enough, but the deployment turned out to be a bit of a puzzle. Particularly as <a href="http://bluehost.com/">bluehost</a>, whose control panel is otherwise excellent, just doesn&#8217;t seem to have its rails story sorted. To make matters worse, every <a href="http://www.google.com/search?q=rails+bluehost">&#8220;rails bluehost&#8221;</a> tutorial out there starts with &#8220;you need SSH access&#8221; and bluehost now requires a <a href="http://helpdesk.bluehost.com/index.php/kb/article/180">faxed or emailed copy of the account-holder&#8217;s drivers license</a> to grant SSH access. Seeing as my clients are generally the hosting account holders, this wasn&#8217;t an option for me.</p>
<p>After a bit of trial and error I&#8217;ve discovered that you can indeed deploy a basic Ruby on Rails site to bluehost without SSH access (assuming you have ftp access). Here&#8217;s how:
</p>
<ol>
<li>
<p><strong style="display:block;">Create rails directory.</strong>Use your ftp client to create a directory alongside the <code>{app}</code> directory to which the domain/sub-domain points.I&#8217;ve called mine <code>{app}_rails</code>, but it can be called anything.</p>
</li>
<li>
<p><strong style="display:block;">Upload rails app.</strong>Upload your rails app into the newly created <code>{app}_rails</code> directory.</p>
</li>
<li>
<p><strong style="display:block;">Symlink to rails public directory using temporary PHP.</strong>We need to <a href="http://en.wikipedia.org/wiki/Symbolic_link">symlink</a> the <code>{app}</code> directory (to which the domain/sub-domain points) to the <code>{app}_rails/public</code> directory. Ordinarily we&#8217;d use the trusty <a href="http://en.wikipedia.org/wiki/Ln_%28Unix%29#Symbolic_link_creation_and_deletion">ln -s</a> command, but we can also do it without SSH access by using <a href="http://php.net/manual/en/function.symlink.php">PHP&#8217;s symlink function</a>.</p>
<p>Create a php script on your local machine (I&#8217;ve called mine <code>symlink.php</code>) with the following contents (replacing the <code>{account}</code> and <code>{app}</code> tokens with your own). Make sure the <code>{app}</code> directory doesn&#8217;t already exist (rename/move/delete it if it does).</p>
<p><code class="snippet"><span class="text"><span class="source"><span class="punctuation">&lt;?php</span> <span class="support">symlink</span>(<span class="string"><span class="punctuation">'</span><span class="meta">/home/atfraser/public_html/maketimelapse_rails/public</span><span class="punctuation">'</span></span>, <span class="string"><span class="punctuation">'</span><span class="meta">/home/atfraser/public_html/maketimelapse</span><span class="punctuation">'</span></span>)<span class="punctuation">;</span> <span class="punctuation"><span class="source">?</span>&gt;</span></span></span></code>
<p>Upload the <code>symlink.php</code> to an accessable directory and then browse to it in your browser. If the script succeeds you&#8217;ll be greeted with a blank page (otherwise you&#8217;ll get errors). Once run successfully, you can delete the symlink php script (it&#8217;s no longer needed).</p>
</li>
<li>
<p><strong style="display:block;">Ensure <code>dispatch.fcgi</code> exists.</strong>To run under apache, a rails app needs fcgi dispatchers. My understanding is that <a href="http://guides.rubyonrails.org/2_3_release_notes.html#other-railties-changes">rails 2.3 no longer fcgi dispatchers by default</a> so if you didn&#8217;t use the <code>--with-dispatches</code> option when you created your app (I didn&#8217;t) you&#8217;ll need to create them on your local machine using the following command:</p>
<p><code class="snippet">rake rails:update:generate_dispatchers</code>
<p>Then upload the created <code>dispatch.fcgi</code>, <code>dispatch.cgi</code> and <code>dispatch.rb</code> files from your local<code>public</code> directory to <code>{app}_rails/public</code> directory on bluehost.</p>
</li>
<li>
<p><strong style="display:block;">Enable <code>dispatch.fcgi</code> in <code>.htaccess</code>.</strong>Create a <code>.htaccess</code> file inside your <code>{app}_rails/public</code> directory with the following contents:</p>
<div class="snippet"><span class="support">AddHandler</span> fcgid-script .fcgi<br/><span class="support">AddHandler</span> cgi-script .cgi<br/><br/><span class="support">RewriteEngine</span> On<br/><br/><span class="support">RewriteBase</span> /<br/><span class="support">RewriteRule</span> <span class="string">^$</span> <span class="string">index.html</span> <span class="string">[QSA]</span><br/><span class="support">RewriteRule</span> <span class="string">^([^.]+)$</span> <span class="string">$1.html</span> <span class="string">[QSA]</span><br/><span class="support">RewriteCond</span> <span class="support"><span class="punctuation">%{</span>REQUEST_FILENAME}</span> <span class="string">!-f</span><br/><span class="support">RewriteRule</span> <span class="string">^(.*)$</span> <span class="string">dispatch.fcgi</span> <span class="string">[QSA,L]</span><br/><br/><span class="support">ErrorDocument</span> 500 <span class="string"><span class="punctuation">&#8220;</span>&lt;h2&gt;Application error&lt;/h2&gt;Rails application failed to start properly<span class="punctuation">&#8220;</span></span></div>
</li>
<li>
<p><strong style="display:block;">Check permissions using FTP client.</strong>We need to check/set some permissions. Again, we can&#8217;t use the standard <code><a href="http://en.wikipedia.org/wiki/Chmod">chmod</a></code> command without SSH access but luckily most modern ftp clients can also view/set permissions (select the file/directory then &#8984;-i in <a href="http://www.panic.com/TRANSMIT/">Transmit</a> or &#8216;right-click &gt; File permissions&#8217; in <a href="http://filezilla-project.org/">FileZilla</a>). Set the appopriate permissions for the following files/directories (list courtesy <a href="http://6brand.com/application-error-rails-app-failed-to-start-properly.html">Jack Danger Canty)</a>: </p>
<table border="0" cellspacing="3" cellpadding="0">
<thead>
<tr>
<th scope="col">File/Directory</th>
<th scope="col">Permission</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding-right:10px;"><code>{app}_rails/public<code></td>
<td>755</td>
</tr>
<tr>
<td style="padding-right:10px;"><code>{app}_rails/public/.htaccess<code></td>
<td>755</td>
</tr>
<tr>
<td style="padding-right:10px;"><code>{app}_rails/public/dispatch.fcgi<code></td>
<td>755</td>
</tr>
<tr>
<td style="padding-right:10px;"><code>{app}_rails/public/dispatch.cgi<code></td>
<td>755</td>
</tr>
<tr>
<td style="padding-right:10px;"><code>{app}_rails/log<code></td>
<td>775</td>
</tr>
<tr>
<td style="padding-right:10px;"><code>{app}_rails/tmp<code></td>
<td>775</td>
</tr>
</tbody>
</table>
</li>
<li>
<p><strong style="display:block;">Handling rails gems version issues.</strong>If you're app still isn't working, check the error logs in cpanel. It may be that the version of the rails version you built against isn't available on the shared host. In this case,you'll need to either freeze the gems into your app locally (then upload the <code>vendor/gems</code> directory) or comment out the following line in <code>environment.rb</code> which refers to their specific version (risky).</p>
<p><code class="snippet">rake rails:freeze:gems</code></li>
</ol>
<p>That should be it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jaysenmarais.com/blog/20100410/deploy_a_rails_app_to_bluehost_without_ssh/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

