<?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>Jeff Owens.com&#187; Rails Archives  &#8211; Jeff Owens.com</title>
	<atom:link href="http://blog.jeff-owens.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jeff-owens.com</link>
	<description>Where Ignorance Is Not Bliss</description>
	<lastBuildDate>Thu, 01 Jul 2010 14:05:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Full Rails Stack Part Four: Capistrano, MySQL</title>
		<link>http://blog.jeff-owens.com/rails/full-rails-stack-part-four-capistrano/</link>
		<comments>http://blog.jeff-owens.com/rails/full-rails-stack-part-four-capistrano/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 17:53:08 +0000</pubDate>
		<dc:creator>Jeff Owens</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://blog.jeff-owens.com/index.php/2008/03/05/full-rails-stack-part-four-capistrano/</guid>
		<description><![CDATA[We completed our subversion setup in part three, now let's add Capistrano deployment to the mix.  Let's go ahead and ssh into our server:
PLAIN TEXT
CODE:




ssh -p 8888 deploy@your_linux_box.com 






Add the following new directories to our server.  This is where our staging and production factory websites will be deployed to:
PLAIN TEXT
CODE:




sudo mkdir /var/www


sudo mkdir [...]]]></description>
			<content:encoded><![CDATA[<p>We completed our subversion setup in part <a href="http://blog.jeff-owens.com/index.php/2008/03/04/full-rails-stack-part-three-project-and-subversion/">three</a>, now let's add Capistrano deployment to the mix.  Let's go ahead and ssh into our server:</p>
<div class="igBar"><span id="lcode-32"><a href="#" onclick="javascript:showPlainTxt('code-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-32">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh -p <span style="color:#800000;color:#800000;">8888</span> deploy@your_linux_box.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Add the following new directories to our server.  This is where our staging and production factory websites will be deployed to:</p>
<div class="igBar"><span id="lcode-33"><a href="#" onclick="javascript:showPlainTxt('code-33'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-33">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo mkdir /var/www</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo mkdir /var/www/apps</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo chown -R deploy:deploy /var/www/apps </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><span id="more-50"></span>Exit out of our linux server.  Run the following command to see a list of our locally installed ruby gems:</p>
<div class="igBar"><span id="lcode-34"><a href="#" onclick="javascript:showPlainTxt('code-34'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-34">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">gem list --local </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Notice we don't have Capistrano installed yet.  Let's rectify that and install some other gems we'll use to add staging ability if we need it on a project:</p>
<div class="igBar"><span id="lcode-35"><a href="#" onclick="javascript:showPlainTxt('code-35'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-35">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo gem install capistrano --include-dependencies</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo gem install capistrano-ext --include-dependencies</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo gem install palmtree --include-dependencies </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Note that sometimes you have to try more than once to install ruby gems.  If you get a timeout error just try it again.  Go ahead and change directories to the new subversion project directory we had created in part three.  Now we will setup our project for Capistrano deployment.</p>
<div class="igBar"><span id="lcode-36"><a href="#" onclick="javascript:showPlainTxt('code-36'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-36">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">capify .</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">cat</span> /dev/null&nbsp; &gt; config/deploy.<span style="">rb</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now paste in the following deploy.rb code from this <a href="http://blog.jeff-owens.com/deploy.rb">link</a> into your deploy.rb file.  Edit the line where it has set :repository and change the IP to your linux server.  Save the file in nano.</p>
<div class="igBar"><span id="lcode-37"><a href="#" onclick="javascript:showPlainTxt('code-37'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-37">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/deploy.<span style="">rb</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Let's create a maintenance page so that if we ever need to take our site down to do server maintenance we're good to go:</p>
<div class="igBar"><span id="lcode-38"><a href="#" onclick="javascript:showPlainTxt('code-38'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-38">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano app/views/layouts/maintenance.<span style="">html</span>.<span style="">erb</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Paste in the html code from this <a href="http://blog.jeff-owens.com/maintenance.txt">link</a> and save the file in nano.  Now let's create the folder structure for our different stages:</p>
<div class="igBar"><span id="lcode-39"><a href="#" onclick="javascript:showPlainTxt('code-39'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-39">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir config/deploy</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir config/deploy/production</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir config/deploy/staging </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Let's create the mongrel_cluster.yml file for production:</p>
<div class="igBar"><span id="lcode-40"><a href="#" onclick="javascript:showPlainTxt('code-40'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-40">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/deploy/production/mongrel_cluster.<span style="">yml</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Paste the following in and then save the file in nano.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">user</span>: deploy</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">group: deploy</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cwd: /var/www/apps/factory/current</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">port: <span style="color:#CC0000;">"9300"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">environment: production</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">address: <span style="color:#800000;color:#800000;">127</span>.<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pid_file: <span style="color:#CC0000;">"/var/run/mongrel_cluster/factory.pid"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">log_file: <span style="color:#CC0000;">"log/factory.log"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">servers: <span style="color:#800000;color:#800000;">3</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's setup staging:</p>
<div class="igBar"><span id="lcode-41"><a href="#" onclick="javascript:showPlainTxt('code-41'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-41">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/deploy/staging/mongrel_cluster.<span style="">yml</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Paste the following in and then save the file in nano.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">user</span>: deploy</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">group: deploy</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cwd: /var/www/apps/qa.<span style="">factory</span>/current</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">port: <span style="color:#CC0000;">"9200"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">environment: staging</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">address: <span style="color:#800000;color:#800000;">127</span>.<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pid_file: <span style="color:#CC0000;">"/var/run/mongrel_cluster/qafactory.pid"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">log_file: <span style="color:#CC0000;">"log/qafactory.log"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">servers: <span style="color:#800000;color:#800000;">2</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>We also need to create a config/environments/staging.rb file:</p>
<div class="igBar"><span id="lcode-42"><a href="#" onclick="javascript:showPlainTxt('code-42'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-42">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/environments/staging.<span style="">rb</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Paste in the following and save in nano</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">config.<span style="">cache_classes</span> = true</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">config.<span style="">action_controller</span>.<span style="">consider_all_requests_local</span> = false</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">config.<span style="">action_controller</span>.<span style="">perform_caching</span> = true</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">config.<span style="">action_view</span>.<span style="">cache_template_loading</span> = true </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's edit our database.yml file and add our stages (make sure to use your mysql user and pwd)</p>
<div class="igBar"><span id="lcode-43"><a href="#" onclick="javascript:showPlainTxt('code-43'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-43">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cat /dev/null&nbsp; &gt; config/database.<span style="">yml</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/database.<span style="">yml</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Paste in the following database info from the following <a href="http://blog.jeff-owens.com/database.yml">link</a> and save the file.  Now we need to add the setup file for production:</p>
<div class="igBar"><span id="lcode-44"><a href="#" onclick="javascript:showPlainTxt('code-44'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-44">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/deploy/production.<span style="">rb</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Paste in the following code and save in nano</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :rails_env, <span style="color:#CC0000;">"production"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :monit_group, <span style="color:#CC0000;">"factory"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :application, <span style="color:#CC0000;">"factory"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :domain, <span style="color:#CC0000;">"www.factory.com"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :server_name, <span style="color:#CC0000;">"www.factory.com"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :deploy_to, <span style="color:#CC0000;">"/var/www/apps/#{application}"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :db_name, <span style="color:#CC0000;">"factory_production"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :db_user, <span style="color:#CC0000;">'root'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :db_passwd, <span style="color:#CC0000;">''</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">role :app, domain</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">role :web, domain</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">role :db,&nbsp; domain, :primary =&gt; true </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now we need to do the same for staging:</p>
<div class="igBar"><span id="lcode-45"><a href="#" onclick="javascript:showPlainTxt('code-45'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-45">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/deploy/staging.<span style="">rb</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Paste in the following code and save in nano</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :rails_env, <span style="color:#CC0000;">"staging"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :monit_group, <span style="color:#CC0000;">"qafactory"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :application, <span style="color:#CC0000;">"qa.factory"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :domain, <span style="color:#CC0000;">"qa.factory.com"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :server_name, <span style="color:#CC0000;">"qa.factory.com"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :deploy_to, <span style="color:#CC0000;">"/var/www/apps/#{application}"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :db_name, <span style="color:#CC0000;">"factory_staging"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :db_user, <span style="color:#CC0000;">'root'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set :db_passwd, <span style="color:#CC0000;">''</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">role :app, domain</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">role :web, domain</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">role :db,&nbsp; domain, :primary =&gt; true </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's setup our fake domain so that we can test our deployment.  Later we can replace a real domain in our staging.rb and production.rb files.</p>
<div class="igBar"><span id="lcode-46"><a href="#" onclick="javascript:showPlainTxt('code-46'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-46">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo nano /etc/hosts</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Add the following line to the bottom of your hosts file making sure to use the ip address of your server</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#800000;color:#800000;">10</span>.<span style="color:#800000;color:#800000;">39</span>.<span style="color:#800000;color:#800000;">121</span>.<span style="color:#800000;color:#800000;">200</span>&nbsp; &nbsp;qa.<span style="">factory</span>.<span style="">com</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#800000;color:#800000;">10</span>.<span style="color:#800000;color:#800000;">39</span>.<span style="color:#800000;color:#800000;">121</span>.<span style="color:#800000;color:#800000;">200</span>&nbsp; &nbsp;www.<span style="">factory</span>.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>You can test it to see if our hosts file change worked by pinging our fake domains:</p>
<div class="igBar"><span id="lcode-47"><a href="#" onclick="javascript:showPlainTxt('code-47'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-47">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ping www.<span style="">factory</span>.<span style="">com</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ping qa.<span style="">factory</span>.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If you get your server's ip address we're good to go.  Now let's test some Capistrano stuff out.  You can see a list of the available Capistrano tasks by typing the following:</p>
<div class="igBar"><span id="lcode-48"><a href="#" onclick="javascript:showPlainTxt('code-48'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-48">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cap -T </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>We are first interested in setting up our staging and production websites folder structure on our linux server.  If we've setup things correctly so far the following commands will do that for us:</p>
<div class="igBar"><span id="lcode-49"><a href="#" onclick="javascript:showPlainTxt('code-49'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-49">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cap staging deploy:setup</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cap production deploy:setup </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's ssh back into our server and see if it worked:</p>
<div class="igBar"><span id="lcode-50"><a href="#" onclick="javascript:showPlainTxt('code-50'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-50">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh -p <span style="color:#800000;color:#800000;">8888</span> deploy@your_linux_box.<span style="">com</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd /var/www/apps</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ls -la </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>You should see two folders, factory and qa.factory.  Now let's install mysql (note that you will be prompted to enter a new password for root):</p>
<div class="igBar"><span id="lcode-51"><a href="#" onclick="javascript:showPlainTxt('code-51'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-51">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Choose the top <span style="color:#006600; font-weight:bold;">&#40;</span>ruby<span style="color:#006600; font-weight:bold;">&#41;</span> option when prompted</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get install mysql-server-<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">0</span> mysql-client-<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">0</span> libmysqlclient15-dev libmysqlclient15off zlib1g-dev libmysql-ruby1.<span style="color:#800000;color:#800000;">8</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#Install MySQL Native Bindings for performance gain</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql/bin/mysql_config </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Next add the following line to your bash profile located in ~/.bash_profile</p>
<div class="igBar"><span id="lcode-52"><a href="#" onclick="javascript:showPlainTxt('code-52'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-52">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano ~/.<span style="">bash_profile</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Add to the top of the file and save in nano</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">export RUBYOPT=rubygems</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Reload your profile</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">source ~/.<span style="">bash_profile</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I like to manually create my databases and users in mysql, so let's add our databases for staging and production.  You'll need to come up with a password you want to use that is secure.  I'm just going to use 'password' for this example.</p>
<div class="igBar"><span id="lcode-53"><a href="#" onclick="javascript:showPlainTxt('code-53'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-53">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql -uroot -p</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">create database factory_staging default character set <span style="color:#CC0000;">'utf8'</span> default collate <span style="color:#CC0000;">'utf8_general_ci'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">create database factory_production default character set <span style="color:#CC0000;">'utf8'</span> default collate <span style="color:#CC0000;">'utf8_general_ci'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">grant all on factory_staging.* to <span style="color:#CC0000;">'factory'</span>@<span style="color:#CC0000;">'localhost'</span> identified by <span style="color:#CC0000;">'password'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">grant all on factory_production.* to <span style="color:#CC0000;">'factory'</span>@<span style="color:#CC0000;">'localhost'</span> identified by <span style="color:#CC0000;">'password'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># You can now see that your two databases were created by typing the following:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">show databases;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Type quit to get out of mysql:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">quit </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Exit out of the server.  Now we need to change our rails project's config/database.yml, config/deploy/staging.rb, and config/deploy/production.rb files to reflect the new mysql user name of 'factory' and your new password.</p>
<div class="igBar"><span id="lcode-54"><a href="#" onclick="javascript:showPlainTxt('code-54'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-54">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Change username and password for the following files and save</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/database.<span style="">yml</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/deploy/staging.<span style="">rb</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/deploy/production.<span style="">rb</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's add all of our rails code changes to subversion. You can see what files we need to add to subversion before we commit by typing the following:</p>
<div class="igBar"><span id="lcode-55"><a href="#" onclick="javascript:showPlainTxt('code-55'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-55">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn status </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The files with the '?' mark in front of them need to be added to subversion:</p>
<div class="igBar"><span id="lcode-56"><a href="#" onclick="javascript:showPlainTxt('code-56'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-56">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn add Capfile</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn add config/deploy</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn add config/deploy.<span style="">rb</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn add config/environments/staging.<span style="">rb</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn add app/views/layouts/maintenance.<span style="">html</span>.<span style="">erb</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's commit everything with a comment:</p>
<div class="igBar"><span id="lcode-57"><a href="#" onclick="javascript:showPlainTxt('code-57'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-57">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn commit -m <span style="color:#CC0000;">"Added files need for capistrano deployment"</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's add our widget tunnel definition to our server and setup ssh keys for our server.  Login to your server:</p>
<div class="igBar"><span id="lcode-58"><a href="#" onclick="javascript:showPlainTxt('code-58'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-58">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh -p <span style="color:#800000;color:#800000;">8888</span> deploy@your_linux_box.<span style="">com</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano ~/.<span style="">subversion</span>/config</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Add the following line inside the <span style="color:#006600; font-weight:bold;">&#91;</span>tunnels<span style="color:#006600; font-weight:bold;">&#93;</span> section and save</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">widgets = /usr/bin/ssh -p <span style="color:#800000;color:#800000;">8888</span> -l deploy</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Now generate ssh keys for our server</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh-keygen -t rsa -f ~/.<span style="">ssh</span>/id_rsa -C <span style="color:#CC0000;">"your@emailaddress.com"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Type the following and copy the entire string that is displayed</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cat ~/.<span style="">ssh</span>/id_rsa.<span style="">pub</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Now paste the string onto the second line of our authorized_keys file and save in nano</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano ~/.<span style="">ssh</span>/authorized_keys </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Exit out of the server.  Now let's try deploying our staging application to the server.  From the root of our factory application type the following:</p>
<div class="igBar"><span id="lcode-59"><a href="#" onclick="javascript:showPlainTxt('code-59'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-59">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cap staging deploy </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>You should see an error at the very bottom (/usr/sbin/monit: command not found).  That's o.k. because we haven't setup monit yet.  So go ahead and deploy production too:</p>
<div class="igBar"><span id="lcode-60"><a href="#" onclick="javascript:showPlainTxt('code-60'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-60">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cap production deploy </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now add our factory tables to our staging and production databases using database migrations:</p>
<div class="igBar"><span id="lcode-61"><a href="#" onclick="javascript:showPlainTxt('code-61'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-61">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cap staging deploy:migrate</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cap production deploy:migrate </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's ssh back into our server and change directories to our deployed websites:</p>
<div class="igBar"><span id="lcode-62"><a href="#" onclick="javascript:showPlainTxt('code-62'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-62">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh -p <span style="color:#800000;color:#800000;">8888</span> deploy@your_linux_box.<span style="">com</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cdapps</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd qa.<span style="">factory</span>/current</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Let<span style="color:#CC0000;">'s use the webrick webserver to test out application out</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">script/server -e staging </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now go to your browser on your Mac and type in http://qa.factory.com:3000.  Our widget listing page should show up if everything is working.  Now try creating a new widget!  To stop the webrick server you just use CTRL_C.  That's it for today.  Next time we will get nginx to run our applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeff-owens.com/rails/full-rails-stack-part-four-capistrano/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Full Rails Stack Part Three: Project and Subversion</title>
		<link>http://blog.jeff-owens.com/rails/full-rails-stack-part-three-project-and-subversion/</link>
		<comments>http://blog.jeff-owens.com/rails/full-rails-stack-part-three-project-and-subversion/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 22:42:03 +0000</pubDate>
		<dc:creator>Jeff Owens</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://blog.jeff-owens.com/index.php/2008/03/04/full-rails-stack-part-three-project-and-subversion/</guid>
		<description><![CDATA[If you've finished part two let's continue.  In this part of the series I'm going to assume you have a working installation of MySQL on your local client machine that we will only need for testing purposes.  If you've got a Mac you might look at installing MacPorts and using it to install [...]]]></description>
			<content:encoded><![CDATA[<p>If you've finished part <a href="http://blog.jeff-owens.com/index.php/2008/02/05/full-rails-stack-part-two/">two</a> let's continue.  In this part of the series I'm going to assume you have a working installation of MySQL on your local client machine that we will only need for testing purposes.  If you've got a Mac you might look at installing MacPorts and using it to install MySQL for you.  First we'll create a test rails project.  I'm going to use the latest rails 2 sugar in setting up this simple test site.  Open up terminal or iTerm and find a directory you want to use to create the test project.  Here we go:</p>
<div class="igBar"><span id="lcode-88"><a href="#" onclick="javascript:showPlainTxt('code-88'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-88">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rails --d=mysql factory</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd factory</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rake db:create</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">script/generate scaffold widget name:string description:text</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rake db:migrate </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's test our site to make sure everything is working correctly:</p>
<div class="igBar"><span id="lcode-89"><a href="#" onclick="javascript:showPlainTxt('code-89'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-89">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">script/server </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Open up your browser and try the site out using http://localhost:3000/widgets.</p>
<p><span id="more-49"></span>Then stop the web server using CTRL_C.  Now let's go ahead and remove the index.html file:</p>
<div class="igBar"><span id="lcode-90"><a href="#" onclick="javascript:showPlainTxt('code-90'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-90">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rm -rf public/index.<span style="">html</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Let's add the default route for our test website so that if you type in localhost:3000 it routes to our widget controller.:</p>
<div class="igBar"><span id="lcode-91"><a href="#" onclick="javascript:showPlainTxt('code-91'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-91">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano config/routes.<span style="">rb</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Paste the following before the 'end' at the bottom of the file</p>
<div class="igBar"><span id="lcode-92"><a href="#" onclick="javascript:showPlainTxt('code-92'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-92">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">map.<span style="">root</span> :controller =&gt; <span style="color:#CC0000;">"widgets"</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Save the file and restart the server:</p>
<div class="igBar"><span id="lcode-93"><a href="#" onclick="javascript:showPlainTxt('code-93'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-93">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">script/server </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Try out our new route by going to http://localhost:3000.  It should load our widgets list page.</p>
<p>Now let's install subversion:</p>
<div class="igBar"><span id="lcode-94"><a href="#" onclick="javascript:showPlainTxt('code-94'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-94">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get install subversion subversion-tools libsvn-dev libsvn1 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Install ssh:</p>
<div class="igBar"><span id="lcode-95"><a href="#" onclick="javascript:showPlainTxt('code-95'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-95">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get install ssh </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Create our repository:</p>
<div class="igBar"><span id="lcode-96"><a href="#" onclick="javascript:showPlainTxt('code-96'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-96">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo svnadmin create /var/svn/mycode</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo chown -R deploy:deploy /var/svn/mycode </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Edit the svnserve config file:</p>
<div class="igBar"><span id="lcode-97"><a href="#" onclick="javascript:showPlainTxt('code-97'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-97">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo nano /var/svn/clickhere/conf/svnserve.<span style="">conf</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Modify the following lines</p>
<div class="igBar"><span id="lcode-98"><a href="#" onclick="javascript:showPlainTxt('code-98'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-98">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">anon-access = none</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">auth-access = write</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">authz-db = /usr/local/nginx/conf/svn_access.<span style="">rules</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">realm = My Code Repository </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Create the access rules file:</p>
<div class="igBar"><span id="lcode-99"><a href="#" onclick="javascript:showPlainTxt('code-99'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-99">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo nano /usr/local/nginx/conf/svn_access.<span style="">rules</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Paste in the following and save the file:</p>
<div class="igBar"><span id="lcode-100"><a href="#" onclick="javascript:showPlainTxt('code-100'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-100">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span>groups<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">developers = deploy</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">qc = deploy</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pm = deploy</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span>/<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@developers = rw</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@qc = r</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@pm = r </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Create a svnserve startup file:</p>
<div class="igBar"><span id="lcode-101"><a href="#" onclick="javascript:showPlainTxt('code-101'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-101">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo nano /etc/init.<span style="">d</span>/svnserve </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Paste in the following:</p>
<div class="igBar"><span id="lcode-102"><a href="#" onclick="javascript:showPlainTxt('code-102'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-102">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#!/bin/sh</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Use the following variables to customize user, group, and paths.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">SVNSERVE</span>=`which svnserve`</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SVN_USER=deploy</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SVN_GROUP=deploy</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SVN_ROOT_PATH=/var/svn/mycode/</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#91;</span> -f /etc/rc.<span style="">d</span>/init.<span style="">d</span>/functions <span style="color:#006600; font-weight:bold;">&#93;</span>; then</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># RedHat style</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">. /etc/rc.<span style="">d</span>/init.<span style="">d</span>/functions</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">START=<span style="color:#CC0000;">"daemon $SVNSERVE -d --root $SVN_ROOT_PATH"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">STOP=<span style="color:#CC0000;">"killproc $SVNSERVE"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">else</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Ubuntu LSB style</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">. /lib/lsb/init-functions</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">START=<span style="color:#CC0000;">"start-stop-daemon --start --exec $SVNSERVE -- -d --root $SVN_ROOT_PATH"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">STOP=<span style="color:#CC0000;">"start-stop-daemon --stop --exec $SVNSERVE"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fi</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#91;</span> ! -x $SVNSERVE <span style="color:#006600; font-weight:bold;">&#93;</span>; then</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"Could not find ${SVNSERVE}. PATH is ${PATH}"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">exit <span style="color:#800000;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fi</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">case <span style="color:#CC0000;">"$1"</span> in</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">start<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"Starting svnserve..."</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">umask <span style="color:#800000;color:#800000;">002</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$START</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#91;</span> $? <span style="color:#006600; font-weight:bold;">&#93;</span>; then</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"Started svnserve"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">exit <span style="color:#800000;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">else</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">exit $?</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fi</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">;;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">stop<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"Stopping svnserve..."</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$STOP</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">exit $?</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">;;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">restart|force-reload<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">"$0"</span> stop &amp;&amp; <span style="color:#CC0000;">"$0"</span> start</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">;;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">*<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"Usage: /etc/init.d/svnserve {start|stop|restart|force-reload}"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">exit <span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">;;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">esac</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"Unhandled case while trying to start svnserve."</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"see $0"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">exit <span style="color:#800000;color:#800000;">3</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Make it executable:</p>
<div class="igBar"><span id="lcode-103"><a href="#" onclick="javascript:showPlainTxt('code-103'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-103">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo chmod +x /etc/init.<span style="">d</span>/svnserve </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Add it to the startup scripts:</p>
<div class="igBar"><span id="lcode-104"><a href="#" onclick="javascript:showPlainTxt('code-104'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-104">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo update-rc.<span style="">d</span> /etc/init.<span style="">d</span>/svnserve defaults </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Start the server:</p>
<div class="igBar"><span id="lcode-105"><a href="#" onclick="javascript:showPlainTxt('code-105'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-105">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo /etc/init.<span style="">d</span>/svnserve start </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Exit it out of our linux server.  Now on our Mac we are going to edit our subversion config file</p>
<div class="igBar"><span id="lcode-106"><a href="#" onclick="javascript:showPlainTxt('code-106'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-106">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo nano ~/.<span style="">subversion</span>/conf </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Add the following line inside the [tunnels] section</p>
<div class="igBar"><span id="lcode-107"><a href="#" onclick="javascript:showPlainTxt('code-107'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-107">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">widgets = /usr/bin/ssh -p <span style="color:#800000;color:#800000;">8888</span> -l deploy </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Save and exit nano.  Now let's try everything out by creating a top level "projects" folder in our subversion repository from our Mac client:</p>
<div class="igBar"><span id="lcode-108"><a href="#" onclick="javascript:showPlainTxt('code-108'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-108">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If the directory got added were good to go.  Now we can add our factory rails website.  But before we do that lets setup a proper subversion folder structure using branches, tags, and trunk.  Below is the folder structure I like (projects/[client_name]/[project_name])...feel free to change it however you'd like it to work.  You could also create the folder structure manually locally on your Mac using mkdir and import it as the project.</p>
<div class="igBar"><span id="lcode-109"><a href="#" onclick="javascript:showPlainTxt('code-109'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-109">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/branches</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/branches/experiments</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/branches/releases</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/branches/tickets</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/tags</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/tags/notable_moments</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/tags/releases</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m <span style="color:#CC0000;">"Creating factory project for me"</span> svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/trunk </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's import our factory project:</p>
<div class="igBar"><span id="lcode-110"><a href="#" onclick="javascript:showPlainTxt('code-110'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-110">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn import -m <span style="color:#CC0000;">"Creating factory project for me"</span> . <span style="">svn</span>+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/trunk </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now we should be able to list the folders using svn:</p>
<div class="igBar"><span id="lcode-111"><a href="#" onclick="javascript:showPlainTxt('code-111'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-111">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn list svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/trunk </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's check out a copy of our factory project from our subversion server.  First we'll create a new directory to hold our code called factorysvn:</p>
<div class="igBar"><span id="lcode-112"><a href="#" onclick="javascript:showPlainTxt('code-112'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-112">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir factorysvn</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd factorysvn</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn co svn+widgets:<span style="color:#FF9933; font-style:italic;">//your_linux_box.com/var/svn/mycode/projects/me/factory/trunk/ . </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now you can edit your rails project and commit your changes using subversion.  That's it for today.  Next we will setup our rails project to use Capistrano and deploy it to our server!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeff-owens.com/rails/full-rails-stack-part-three-project-and-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Full Rails Stack Part 2: Rails, Mongrel and Nginx</title>
		<link>http://blog.jeff-owens.com/rails/full-rails-stack-part-two/</link>
		<comments>http://blog.jeff-owens.com/rails/full-rails-stack-part-two/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 18:25:19 +0000</pubDate>
		<dc:creator>Jeff Owens</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://blog.jeff-owens.com/index.php/2008/02/05/full-rails-stack-part-two/</guid>
		<description><![CDATA[We completed setting up ssh and ssh keys in part one, let's continue now with part two of installing a full Rails stack.
SSH into your server:
PLAIN TEXT
CODE:




ssh -p 8888 deploy@your_linux_box.com 






By default, Debian and Ubuntu have ﬁve package repositories called main, restricted, universe, multiverse, and commercial. You will need the universe package repository. By default, [...]]]></description>
			<content:encoded><![CDATA[<p>We completed setting up ssh and ssh keys in part <a href="http://blog.jeff-owens.com/index.php/2008/02/04/full-rails-stack-with-nginx-mongrel-monit-and-more/">one</a>, let's continue now with part two of installing a full Rails stack.</p>
<p>SSH into your server:</p>
<div class="igBar"><span id="lcode-127"><a href="#" onclick="javascript:showPlainTxt('code-127'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-127">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh -p <span style="color:#800000;color:#800000;">8888</span> deploy@your_linux_box.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>By default, Debian and Ubuntu have ﬁve package repositories called main, restricted, universe, multiverse, and commercial. You will need the universe package repository. By default, it may or may not be enabled. To check, edit the /etc/apt/sources.list ﬁle (note that if you didn't install the aliases in part one you'll use "sudo nano" instead of sn below):</p>
<p><span id="more-48"></span></p>
<div class="igBar"><span id="lcode-128"><a href="#" onclick="javascript:showPlainTxt('code-128'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-128">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sn /etc/apt/sources.<span style="">list</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Uncomment the following two lines (assuming Ubuntu Feisty is installed):</p>
<div class="igBar"><span id="lcode-129"><a href="#" onclick="javascript:showPlainTxt('code-129'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-129">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">deb http:<span style="color:#FF9933; font-style:italic;">//us.archive.ubuntu.com/ubuntu/ feisty universe</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">deb-src http:<span style="color:#FF9933; font-style:italic;">//us.archive.ubuntu.com/ubuntu/ feisty universe </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Save and exit nano.</p>
<p>Now, lets make sure our server packages are up to date (note that in all of the installs for our Rails stack if you are prompted with "yes/no" say yes:</p>
<div class="igBar"><span id="lcode-130"><a href="#" onclick="javascript:showPlainTxt('code-130'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-130">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get update</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get upgrade </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Install the GCC Tool Chain:</p>
<div class="igBar"><span id="lcode-131"><a href="#" onclick="javascript:showPlainTxt('code-131'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-131">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get install build-essential </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now lets create a src directory to build from and get ruby and friends setup:</p>
<div class="igBar"><span id="lcode-132"><a href="#" onclick="javascript:showPlainTxt('code-132'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-132">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd ~/</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir src</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd src</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wget ftp:<span style="color:#FF9933; font-style:italic;">//ftp.gnu.org/gnu/readline/readline-5.2.tar.gz</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wget ftp:<span style="color:#FF9933; font-style:italic;">//ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tar zxvf ruby-<span style="color:#800000;color:#800000;">1</span>.<span style="color:#800000;color:#800000;">8</span>.<span style="color:#800000;color:#800000;">6</span>.<span style="">tar</span>.<span style="">gz</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tar zxvf readline-<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">2</span>.<span style="">tar</span>.<span style="">gz</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd readline-<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">2</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">./configure</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">make</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo make install</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd ../ruby-<span style="color:#800000;color:#800000;">1</span>.<span style="color:#800000;color:#800000;">8</span>.<span style="color:#800000;color:#800000;">6</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get build-dep ruby1.<span style="color:#800000;color:#800000;">8</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">./configure</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">make</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo make install </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Install other core packages:</p>
<div class="igBar"><span id="lcode-133"><a href="#" onclick="javascript:showPlainTxt('code-133'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-133">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get install ri rdoc irb ri1.<span style="color:#800000;color:#800000;">8</span> ruby1.<span style="color:#800000;color:#800000;">8</span>-dev libzlib-ruby zlib1g </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Install RubyGems:</p>
<div class="igBar"><span id="lcode-134"><a href="#" onclick="javascript:showPlainTxt('code-134'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-134">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd ..</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">wget</span> http:<span style="color:#FF9933; font-style:italic;">//rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tar xvzf rubygems-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">9</span>.<span style="color:#800000;color:#800000;">4</span>.<span style="">tgz</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd rubygems-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">9</span>.<span style="color:#800000;color:#800000;">4</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo ruby setup.<span style="">rb</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Install Ruby on Rails and Dependencies (the following will download the latest framework):</p>
<div class="igBar"><span id="lcode-135"><a href="#" onclick="javascript:showPlainTxt('code-135'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-135">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo gem install rails --include-dependencies --no-rdoc --no-ri </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If you need a specific version of rails here is an example which gets version 1.2.5:</p>
<div class="igBar"><span id="lcode-136"><a href="#" onclick="javascript:showPlainTxt('code-136'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-136">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo gem install rails -v <span style="color:#800000;color:#800000;">1</span>.<span style="color:#800000;color:#800000;">2</span>.<span style="color:#800000;color:#800000;">5</span> --include-dependencies --no-rdoc --no-ri </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now let's install Mongrel (make sure you select the top ruby option when prompted):</p>
<div class="igBar"><span id="lcode-137"><a href="#" onclick="javascript:showPlainTxt('code-137'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-137">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo gem install mongrel mongrel_cluster --include-dependencies --no-rdoc --no-ri </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now we need to install some packages in preparation for Nginx:</p>
<div class="igBar"><span id="lcode-138"><a href="#" onclick="javascript:showPlainTxt('code-138'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-138">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo apt-get install libpcre3-dev libpcre3 libpcrecpp0 openssl libssl-dev </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Grab the latest build of Nginx:</p>
<div class="igBar"><span id="lcode-139"><a href="#" onclick="javascript:showPlainTxt('code-139'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-139">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd ~/src</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wget http:<span style="color:#FF9933; font-style:italic;">//sysoev.ru/nginx/nginx-0.5.35.tar.gz</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tar xzvf nginx-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">35</span>.<span style="">tar</span>.<span style="">gz</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd nginx-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">35</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">./configure --sbin-path=/usr/local/sbin --with-http_ssl_module</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">make</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo make install </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Check that nginx is working and in your $PATH. The version command option should do the trick:</p>
<div class="igBar"><span id="lcode-140"><a href="#" onclick="javascript:showPlainTxt('code-140'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-140">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nginx -v</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nginx version: nginx/<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">35</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>That's it for today.  Next time we will setup the Nginx configuration files for our website and continue to add new functionality to our stack.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeff-owens.com/rails/full-rails-stack-part-two/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Full Rails Stack With Nginx, Mongrel, Monit, And More</title>
		<link>http://blog.jeff-owens.com/rails/full-rails-stack-with-nginx-mongrel-monit-and-more/</link>
		<comments>http://blog.jeff-owens.com/rails/full-rails-stack-with-nginx-mongrel-monit-and-more/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 21:52:42 +0000</pubDate>
		<dc:creator>Jeff Owens</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.jeff-owens.com/index.php/2008/02/04/full-rails-stack-with-nginx-mongrel-monit-and-more/</guid>
		<description><![CDATA[I enjoy coding websites.  I like coming up with elegant and flexible solutions to problems.  If you saw David Heinemeier Hanssons' early screen casts on web development with Ruby on Rails, you may have been as impressed as I was.  Unfortunately, deployment of a website to a *nix server can be a [...]]]></description>
			<content:encoded><![CDATA[<p>I enjoy coding websites.  I like coming up with elegant and flexible solutions to problems.  If you saw David Heinemeier Hanssons' early screen casts on web development with Ruby on Rails, you may have been as impressed as I was.  Unfortunately, deployment of a website to a *nix server can be a daunting task if you haven't done it before.  It doesn't matter if it is a PHP, Python, or Ruby on Rails website, you need to have some basic sysadmin skills to set everything up on a newly installed server.  You've got to know something about web servers (Apache, NginX, etc.), something about databases (MySQL, Postgres), about firewalls (iptables or Shorewall), source control (Subversion), email (SendMail, Postfix), monitoring your server (Monit, Nagios), statistics (Awstats, etc.), log rotation, cron jobs, offsite backups (Amazon s3).  I have yet to meet an expert in all of these areas.  For those sysadmins out there that fit the description I bow deeply.  I've decided to do a series on setting up a full Rails stack on Ubuntu.  So far I have deployed production Rails web applications to Red Hat, Open Solaris, CentOS, and Ubuntu servers.  I've learned enough to know how truly ignorant I am.  I don't claim to be an expert.  But I am willing to share what I've learned so far in hopes it will help others out there.  Here is what you'll get (in no particular order) when finished with the series.<span id="more-47"></span></p>
<ul>
<li>SSH Keys</li>
<li>Setting Up Aliases</li>
<li>Nginx</li>
<li>Ruby, RubyGems, Rails</li>
<li>ImageMagick, RMagick</li>
<li>Mongrel, Mongrel Cluster</li>
<li>Monit</li>
<li>AwStats</li>
<li>Webmin</li>
<li>Postfix</li>
<li>MySQL</li>
<li>Log Rotation</li>
<li>Capistrano 2 Deployment</li>
<li>Webistrano setup</li>
<li>Amazon s3 backup</li>
<li>Cron Job setup</li>
<li>Subversion</li>
<li>Shorewall Firewall</li>
</ul>
<p>The usual disclaimer applies about not blaming me if things go awry on your machine.  The following is working great for me right now on production servers.  Your mileage may vary.</p>
<p>But, before we begin, please note that I am aware of the many automated ways that are available to setup a server such as RubyWorks by ThoughtWorks, the RailsMachine gem, Machinify, deprec, etc.  When I first was learning about deployment I tried most of these out.  Unfortunately, in my opinion, if you don't know how, where, and why things are installed on your server, it can lead to problems in the future.  Trust me, it is much better to learn about how things work up front, that way you can deal with unique client requests that these automated solutions can't possibly account for.  For example, I just recently deployed a Ruby on Rails forum that uses a Microsoft SQLServer 2000 database the client already had and wanted to use.  If I hadn't learned some basic sysadmin skills, I would have been up a creek.</p>
<p>So let's get started.  Here are my basic assumptions.  You've got a brand new *nix server (the commands will assume Ubuntu Linux but the steps used can be applied to any *nix server) installed that is up and running.  If you don't have a server I would recommend looking at <a href="http://www.slicehost.com/">SliceHost</a> for small to medium sites.  They are affordable and have been quite reliable for me (they run VPS slices on Xen servers).  You should have the SSH credentials for the server.  You also need a way to SSH into the server.  For Mac it is built in (Terminal application), on a PC you can download <a href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe">Putty</a>.  Lets do a quick connection test and setup a new user on the server.  Open up Terminal or Putty and connect to your server (you will be prompted for your password):</p>
<div class="igBar"><span id="lcode-160"><a href="#" onclick="javascript:showPlainTxt('code-160'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-160">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh root@your_linux_box.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now create a new user called deploy:</p>
<div class="igBar"><span id="lcode-161"><a href="#" onclick="javascript:showPlainTxt('code-161'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-161">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">adduser deploy </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now lets grant our new user sudo access.  Type "visudo" and scroll down to the bottom and add our deploy user under the root section:</p>
<div class="igBar"><span id="lcode-162"><a href="#" onclick="javascript:showPlainTxt('code-162'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-162">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo visudo</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">deploy ALL=<span style="color:#006600; font-weight:bold;">&#40;</span>ALL<span style="color:#006600; font-weight:bold;">&#41;</span> ALL </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Save the file and exit out of the text editor.  Type "exit" to get out of our ssh sesssion and return to our client machine.  Change directories to your home directory on your Mac:</p>
<div class="igBar"><span id="lcode-163"><a href="#" onclick="javascript:showPlainTxt('code-163'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-163">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd ~ </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Our first full step is one of convenience for Mac users and isn't absolutely necessary.  We are going to setup SSH keys so that we won't be prompted for a password every time we want to SSH into our server. This will make our Capistrano deployments seamless later on.  First we need to create a public key on our Mac.  You can generate an SSH RSA key with your email as an added comment using the ssh-keygen command. The following command will create two files, id_rsa and id_rsa.pub, in your .ssh/ directory:</p>
<div class="igBar"><span id="lcode-164"><a href="#" onclick="javascript:showPlainTxt('code-164'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-164">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh-keygen -t rsa -f ~/.<span style="">ssh</span>/id_rsa -C <span style="color:#CC0000;">"your@emailaddress.com"</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now lets create the .ssh directory on our server.  We can actually create this folder without executing any commands on the Linux server. We use SSH to remotely execute the command from our client machine so you <strong>don't</strong> need to run the following command on your Linux server.</p>
<div class="igBar"><span id="lcode-165"><a href="#" onclick="javascript:showPlainTxt('code-165'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-165">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh deploy@your_linux_box.<span style="">com</span> <span style="color:#CC0000;">'mkdir ~/.ssh;chmod 700 ~/.ssh'</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>With the .ssh directory prepared on your Linux server you need to copy your public key to the .ssh/authorized_keys file. Then we make sure the permissions on that file allow only the deploy user read and write access:</p>
<div class="igBar"><span id="lcode-166"><a href="#" onclick="javascript:showPlainTxt('code-166'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-166">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">scp ~/.<span style="">ssh</span>/id_rsa.<span style="">pub</span> deploy@your_linux_box.<span style="">com</span>:~/.<span style="">ssh</span>/authorized_keys</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh deploy@your_linux_box.<span style="">com</span> <span style="color:#CC0000;">'chmod 600 ~/.ssh/authorized_keys'</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now you have created and deployed your SSH keypair.  Using the keys you have just created you can deploy your apps effortlessly with Capistrano.  Now lets modify the default port and login permissions for SSH to really lock it down.  SSH into the server again, note that this time you won't be prompted for a password!</p>
<div class="igBar"><span id="lcode-167"><a href="#" onclick="javascript:showPlainTxt('code-167'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-167">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh deploy@your_linux_box.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Edit the SSHD File:</p>
<div class="igBar"><span id="lcode-168"><a href="#" onclick="javascript:showPlainTxt('code-168'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-168">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo nano /etc/ssh/sshd_conﬁg </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Edit the line that looks like this:</p>
<div class="igBar"><span id="lcode-169"><a href="#" onclick="javascript:showPlainTxt('code-169'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-169">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Port <span style="color:#800000;color:#800000;">22</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Change it to:</p>
<div class="igBar"><span id="lcode-170"><a href="#" onclick="javascript:showPlainTxt('code-170'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-170">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Port <span style="color:#800000;color:#800000;">8888</span> # or any unused port above <span style="color:#800000;color:#800000;">1024</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Edit the line that says PermitRootLogin yes and change it to:</p>
<div class="igBar"><span id="lcode-171"><a href="#" onclick="javascript:showPlainTxt('code-171'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-171">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">PermitRootLogin no </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Then save the ﬁle and quit the editor. And don’t forget to restart the SSH server daemon:</p>
<div class="igBar"><span id="lcode-172"><a href="#" onclick="javascript:showPlainTxt('code-172'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-172">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sudo /etc/init.<span style="">d</span>/ssh reload </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>From now on you won't be able to SSH into your server as root which is a good thing.  You will also have to pass the port number to ssh when logging in from now on.  We added this for a little more security. This is how to add the port when logging in now:</p>
<div class="igBar"><span id="lcode-173"><a href="#" onclick="javascript:showPlainTxt('code-173'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-173">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh -p <span style="color:#800000;color:#800000;">8888</span> deploy@your_linux_box.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>For you security buffs out there, yes I know this is security through obscurity.  We will lock our server down with a firewall later on.  If you are on a Mac, may I suggest you download the great terminal replacement application called <a href="http://iterm.sourceforge.net/download.shtml">iTerm</a>.  What I really like about iTerm is that you can have multiple SSH instances running in different tabs by hitting (APPLE + T).  You can also add bookmarks for all of the servers you need to constantly SSH into.  Once you've setup your SSH keys and added your login information to iTerm, you just click on the bookmark and you're logged into your server!  Now that's convenience.</p>
<p>Let's go ahead and log back into our server and add some bash command aliases to make our life easier:</p>
<div class="igBar"><span id="lcode-174"><a href="#" onclick="javascript:showPlainTxt('code-174'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-174">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ssh -p <span style="color:#800000;color:#800000;">8888</span> deploy@your_linux_box.<span style="">com</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Let's create a bash profile:</p>
<div class="igBar"><span id="lcode-175"><a href="#" onclick="javascript:showPlainTxt('code-175'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-175">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">nano .<span style="">bash_profile</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Copy and paste into the nano text editor the following commands (note that some of these commands are Debian/Ubuntu specific and won't work yet until we complete our Rails stack):</p>
<div class="igBar"><span id="lcode-176"><a href="#" onclick="javascript:showPlainTxt('code-176'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-176">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">export PS1=<span style="color:#CC0000;">'<span style="color:#000099; font-weight:bold;">\[</span><span style="color:#000099; font-weight:bold;">\0</span>33[0;35m<span style="color:#000099; font-weight:bold;">\]</span><span style="color:#000099; font-weight:bold;">\h</span><span style="color:#000099; font-weight:bold;">\[</span><span style="color:#000099; font-weight:bold;">\0</span>33[0;33m<span style="color:#000099; font-weight:bold;">\]</span> <span style="color:#000099; font-weight:bold;">\w</span><span style="color:#000099; font-weight:bold;">\[</span><span style="color:#000099; font-weight:bold;">\0</span>33[00m<span style="color:#000099; font-weight:bold;">\]</span>: '</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias space=<span style="color:#CC0000;">' sudo find / -mount -size +2000 -exec ls -s {} <span style="color:#000099; font-weight:bold;">\;</span> | sort -nr | more'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias os=<span style="color:#CC0000;">'cat /etc/issue'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias free=<span style="color:#CC0000;">"free -m"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias update=<span style="color:#CC0000;">"sudo aptitude update"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias install=<span style="color:#CC0000;">"sudo aptitude install"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias upgrade=<span style="color:#CC0000;">"sudo aptitude safe-upgrade"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias remove=<span style="color:#CC0000;">"sudo aptitude remove"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias pg=<span style="color:#CC0000;">'ps -afe|grep -v grep|grep'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias cdapps=<span style="color:#CC0000;">'cd /var/www/apps'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias startmg=<span style="color:#CC0000;">'sudo mongrel_rails cluster::start'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias stopmg=<span style="color:#CC0000;">'sudo mongrel_rails cluster::stop'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias n=<span style="color:#CC0000;">'nano'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias sn=<span style="color:#CC0000;">'sudo nano'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias q=<span style="color:#CC0000;">'quit'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias ..=<span style="color:#CC0000;">'cd ..;ls -la | more'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias cd..=<span style="color:#CC0000;">'cd ..'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alias hm=<span style="color:#CC0000;">'cd ~;ls -la | more'</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now exit and save the file.  Type the following to load the changes we made:</p>
<div class="igBar"><span id="lcode-177"><a href="#" onclick="javascript:showPlainTxt('code-177'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-177">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">source .<span style="">bash_profile</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now try the free command to see how much memory we have available on our server (the last line is what you want to look at (the <strong>used/free</strong> columns):</p>
<div class="igBar"><span id="lcode-178"><a href="#" onclick="javascript:showPlainTxt('code-178'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-178">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">free </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If it worked you should see some output columns in your terminal window.  Now go ahead and type exit and log out of your server.  We're done for today.  Next time we will get busy installing software on our shiny new server.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeff-owens.com/rails/full-rails-stack-with-nginx-mongrel-monit-and-more/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
