<?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>redconfettipassenger | redconfetti</title>
	<atom:link href="http://www.redconfetti.com/tag/passenger/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redconfetti.com</link>
	<description>the journal of maxwell keyes</description>
	<lastBuildDate>Tue, 24 Jan 2012 17:04:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rails 3 on WHM / cPanel VPS Server</title>
		<link>http://www.redconfetti.com/2012/01/rails-3-on-whm-cpanel-vps-server/</link>
		<comments>http://www.redconfetti.com/2012/01/rails-3-on-whm-cpanel-vps-server/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 17:14:58 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[cpanel]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails3.1]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=998</guid>
		<description><![CDATA[cPanel is working towards making Rails 3 applications run natively with Passenger, setup via the cPanel interface. I&#8217;m not really sure if this will be ideal, as most organizations deploy their apps to the server using Capistrano, not uploading via FTP or something. I&#8217;ve been hosting a number of PHP driven sites, including this blog,...]]></description>
			<content:encoded><![CDATA[<p>cPanel is <a href="http://forums.cpanel.net/f145/mod_rails-passenger-instead-mongrel-rails-3-support-case-44197-a-152577-p3.html" target="_blank">working towards making Rails 3 applications run natively</a> with Passenger, setup via the cPanel interface. I&#8217;m not really sure if this will be ideal, as most organizations deploy their apps to the server using Capistrano, not uploading via FTP or something.</p>
<p>I&#8217;ve been hosting a number of PHP driven sites, including this blog, from a shared hosting service for quite a while now. Shared hosting is fine for personal websites or even small businesses with 4-5 page brochure style websites that do not receive lots of traffic, but they&#8217;re not fine if slow performance or intermittent downtime causes you to loose business (or even the respect of your visitors). In such cases I recommend a VPS, because you control who you&#8217;re hosting and thus can ensure optimal uptime and performance. I highly recommend <a href="http://www.linode.com/" target="_blank">Linode</a> as a VPS provider.</p>
<p>I&#8217;ve been using the shared hosting for PHP/Wordpress sites, and a VPS to host the Ruby on Rails applications I&#8217;ve been working on. Really this is expensive, so I&#8217;m wanting to consolidate to one VPS for everything.</p>
<p>I&#8217;ve been forewarned that cPanel does things it&#8217;s own way, so if you&#8217;re trying to do something out-of-the-box you can run into issues. I&#8217;m aware of this, and through this article will let you know if setting up a Rails 3.1.3 hosting environment is possible with a WHM / cPanel server (RELEASE version 11.30.5, build 3). I plan on using Gitosis under an account to host repositories, Capistrano for deployment, and Passenger with Apache2 already provided by cPanel.</p>
<h2>Installing Ruby</h2>
<p>To stay within the &#8220;box&#8221; of the cPanel environment, I installed Ruby using the script provided by cPanel </p>
<pre class="brush:shell">
/scripts/installruby
</pre>
<h2>Gitosis</h2>
<p>To setup Gitosis you have to first install Python tools.</p>
<pre class="brush:shell">
yum -y install python-setuptools
</pre>
<p>Next, to install Git, you&#8217;ll have to use a special command because cPanel has configured /etc/yum.conf to exclude certain packages, including perl packages, so that they do not break or conflict with the cPanel system. Use the following command to install Git:</p>
<pre class="brush:shell">
yum --disableexcludes=main install git
</pre>
<p>From the root home directory, download and install Gitosis.</p>
<pre class="brush:shell">
cd /root
git clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install
</pre>
<p>Next create an account to host your Git repositories from the WHM interface. I&#8217;ve added a user with the user name &#8216;git&#8217;, and used &#8216;git.web-app-host.com&#8217; as the domain (a subdomain under my hosting service domain). Set the password to a very long secure password. You won&#8217;t be needing it again, as you&#8217;ll be using an SSH key to authenticate.</p>
<p>After you&#8217;re done creating the cPanel account which will host the repositories, copy your public key from your local machine to your root users home direcotry ( /root/ ).</p>
<pre class="brush:shell">
scp ~/.ssh/id_rsa.pub root@vps.web-app-host.com:/root
</pre>
<p>Go back to your SSH session as &#8216;root&#8217; on the server and run this command to initialize the Gitosis repository under the &#8216;git&#8217; user account.</p>
<pre class="brush:shell">
root@vps [~]# sudo -H -u git gitosis-init < /root/id_rsa.pub
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/
</pre>
<p>NOTE: Do not use the 'Manage SSH Keys' option from the cPanel for the Git acccount, as this will remove the Gitosis-admin repository key from /home/git/.ssh/authorized_keys.</p>
<p>Run the following command to make sure the post-update hook is executable. If this isn't done, then tasks performed by Gitosis after you commit an update aren't performed (i.e. creating new repositories).</p>
<pre class="brush:shell">
sudo chmod u+x /home/git/repositories/gitosis-admin.git/hooks/post-update
</pre>
<p>On your local machine, run the following command to clone the Gitosis-admin repository, used to manage your repositories on the server, to your local machine.</p>
<pre class="brush:shell">
git clone git@<YOURSERVER>:gitosis-admin.git
</pre>
<p>This should look like this:</p>
<pre class="brush:shell">
$ git clone git@vps.web-app-host.com:gitosis-admin.git
Cloning into 'gitosis-admin'...
stdin: is not a tty
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 5 (delta 0)
Receiving objects: 100% (5/5), done.
</pre>
<hr />
Note: If you are prompted for a password when running this clone command, you likely have some sort of SSH configuration not setup properly on your local machine. If you're using multiple keys with various hosts, check ~/.ssh/config and make sure you're using the proper syntax. Run 'ssh git@<YOURSERVER> -v' to get a verbose output of what's happening when the SSH session is initialized to investigate further.</p>
<hr />
<p>On the remote machine, go ahead and delete your public key from the root users home directory.</p>
<pre class="brush:shell">
rm /root/id_rsa.pub
</pre>
<p>After cloning the Gitosis repository to your local machine, you simply modify and commit changes to the 'gitosis.conf' file inside of the 'gitosis-admin' folder.</p>
<p>If you're configuring new users, simply add their public SSH keys to the 'keydir' folder with the '.pub' file extension. Refer to these users using the filename of the public key file without the '.pub' extension.</p>
<p>For instance I've added a repository called 'marketsim', and then added 'marketsim' to the 'writable' setting for the gitosis-admin group.</p>
<pre class="brush:text">
[gitosis]

[group gitosis-admin]
writable = gitosis-admin marketsim
members = jason@mymacbook.local

[repo marketsim]
gitweb = no
description = Market Simulation App
owner = Jason Miller
daemon = no
</pre>
<p>Alternatively I could create a new group with writable access to the 'marketsim' repository.</p>
<pre class="brush:text">
[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = jason@mymacbook.local

[group marketsim-team]
members = jason@mymacbook.local
writable = marketsim

[repo marketsim]
gitweb = no
description = Market Simulation App
owner = Jason Miller
daemon = no
</pre>
<p>I could add 'newteammember.pub' in the 'keydir' folder, then add 'newteammember' after 'jason@mymacbook.local' separated by a space. This would make another team member part of that group which has write access to the repository.</p>
<p>After configuring a new repository, and giving my own local user write access to that repository, I've push the changes via a commit to the remote gitosis-admin repository.</p>
<p>NOTE: You may receive the warning "remote: WARNING:gitosis.gitweb.set_descriptions:Cannot find 'yourrepo' in '/home/git/repositories'". Ignore this and continue.</p>
<p>Now I'm going to initialize my new repository and push it to the remote server.</p>
<pre class="brush:shell">
$ cd marketsim
$ git init .
$ git add .
$ git commit -m "initial commit"
$ git remote add origin git@vps.web-app-host.com:marketsim.git
$ git push origin master
stdin: is not a tty
Initialized empty Git repository in /home/git/repositories/marketsim.git/
Counting objects: 3, done.
Writing objects: 100% (3/3), 209 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@vps.web-app-host.com:marketsim.git
 * [new branch]      master -> master
</pre>
<h2>Deploying to Server</h2>
<p>I've created an account with the username 'marketsi' to host the deployed application (cPanel only allows up to 8 characters for the username). Then I've logged into that account and added my public key via the SSH/Shell Access > Manage SSH Keys section of the cPanel account. </p>
<p>For property deployment you'll need to install the 'Bundler' gem so that the deployment script can install the gems needed for your application. You'll need to install this as 'root' so that the 'bundle' script is available under /usr/bin/bundle.</p>
<pre class="brush:shell">
$ ssh root@vps.web-app-host.com
root@vps [~]# gem install bundler
Fetching: bundler-1.0.21.gem (100%)
Successfully installed bundler-1.0.21
1 gem installed
Installing ri documentation for bundler-1.0.21...
Installing RDoc documentation for bundler-1.0.21...
root@vps [~]# which bundle
/usr/bin/bundle
</pre>
<p>I've modified my deploy.rb file for my Rails application like so:</p>
<pre class="brush:rails">
require "bundler/capistrano"
load "deploy/assets"

#############################################################
# Settings

set :application, "marketsim"
default_run_options[:pty] = true  # Must be set for the password prompt from git to work
set :use_sudo, false

set :user, "marketsi"  # The server's user for deploys
set :deploy_to, "/home/#{user}/rails"
set :ssh_options, { :forward_agent => true }

set :domain, "marketsim.org"
server domain, :app, :web
role :db, domain, :primary => true

#############################################################
# Git

set :scm, :git
set :repository,  "git@vps.web-app-host.com:marketsim.git"
set :branch, "master"
set :deploy_via, :remote_cache

#############################################################
# Passenger

namespace :passenger do
  desc "Restart Application"
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

after :deploy, "passenger:restart"
</pre>
<p>Now to run the script to setup the deployment directories on the remote server.</p>
<pre class="brush:shell">
cap deploy:setup
</pre>
<p>This created a folder under /home/marketsi/rails with the 'releases' and 'shared' folder. Now I'll actually deploy.</p>
<pre class="brush:shell">
cap deploy
</pre>
<p>The gems were installed with no issue by Bundler for me. Hopefully the same goes for you.</p>
<h2>Passenger</h2>
<p>The next step is to configure Apache to serve the Rails application for my domain name. Install the Passenger gem via SSH logged in as root:</p>
<pre class="brush:shell">
gem install passenger
</pre>
<p>Install Passenger using the Apache module installation command. All dependencies should be found and displayed in green.</p>
<pre class="brush:shell">
passenger-install-apache2-module
</pre>
<p>At the end of the installation script it provides the Apache configuration settings which you place in httpd.conf. Since we're using cPanel, which over-writes the Apache configuration when the EasyApache system is used to rebuild Apache, PHP, and other modules, place this configuration in /usr/local/apache/conf/includes/pre_main_global.conf.</p>
<pre class="brush:text">
# /usr/local/apache/conf/includes/pre_main_global.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11
PassengerRuby /usr/bin/ruby
</pre>
<p>Next make a backup of the httpd.conf, run the configuration distiller script, rebuild, and then restart Apache.</p>
<pre class="brush:shell">
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak-modrails
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
</pre>
<p>The cPanel system makes the Apache Document Root for each account map to /home/username/public_html. Because of this you will need to remove the 'public_html' directory, and then create a symlink from that directory to the 'public' directory for your applications current release:</p>
<pre class="brush:shell">
rm -rf /home/marketsi/public_html/
ln -s /home/marketsi/rails/current/public /home/marketsi/public_html
chown marketsi:nobody public_html/
chmod 750 public_html/
</pre>
<p>Next add a .htaccess file in your application under the 'public' folder, and make sure it contains 'RailsBaseURI /', as well as a directive with the PassengerAppRoot.</p>
<pre class="brush:rails">
RailsBaseURI /
PassengerAppRoot /home/marketsi/rails/current
</pre>
<h2>MySQL Database</h2>
<p>If your application returns an error page 'We're sorry, but something went wrong.', check the production.log file on the server. In my case, the application was running, but it couldn't connect to the database with the existing database.yml settings for production.</p>
<p>As cPanel controls the MySQL databases and usernames, you'll have to create a database manually via the cPanel, create the user and assign all privileges to it for the database, and then configure your database.yml appropriately.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2012/01/rails-3-on-whm-cpanel-vps-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up Deployment for Rails using Capistrano, Apache with Passenger and Git</title>
		<link>http://www.redconfetti.com/2010/07/setting-up-deployment-for-rails-using-capistrano-apache-with-passenger-and-git/</link>
		<comments>http://www.redconfetti.com/2010/07/setting-up-deployment-for-rails-using-capistrano-apache-with-passenger-and-git/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 03:48:23 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=556</guid>
		<description><![CDATA[I don&#8217;t have time right now to learn how to setup Capistrano. I just want a recipe that works and does the job. Here are my notes. 1) First install the Capistrano gem sudo gem install capistrano 2) Next you need to go into the directory of your Ruby on Rails application and capify it:...]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t have time right now to learn how to setup Capistrano. I just want a recipe that works and does the job. Here are my notes.</p>
<p>1) First install the Capistrano gem</p>
<pre class="brush:bash">sudo gem install capistrano</pre>
<p>2) Next you need to go into the directory of your Ruby on Rails application and capify it:</p>
<pre class="brush:bash">capify .</pre>
<p>3) Next I recommend this article (I&#8217;ll rip off the deploy.rb soon and post it here)</p>
<p><a href="http://www.zorched.net/2008/06/17/capistrano-deploy-with-git-and-passenger/" target="_blank">http://www.zorched.net/2008/06/17/capistrano-deploy-with-git-and-passenger/</a></p>
<p>4) Once you&#8217;ve configured your deploy.rb, run this command to have it setup the directories on the remote server (releases, shared, logs, etc).</p>
<pre class="brush:bash">cap deploy:setup</pre>
<p>5) Next run this command to get the list of other capistrano commands you can run:</p>
<pre class="brush:bash">cap -T</pre>
<p>The output should look like</p>
<pre class="brush:bash">
cap deploy               # Deploys your project.
cap deploy:check         # Test deployment dependencies.
cap deploy:cleanup       # Clean up old releases.
cap deploy:cold          # Deploys and starts a `cold' application.
cap deploy:migrate       # Run the migrate rake task.
cap deploy:migrations    # Deploy and run pending migrations.
cap deploy:pending       # Displays the commits since your last deploy.
cap deploy:pending:diff  # Displays the `diff' since your last deploy.
cap deploy:restart       # Restarting mod_rails with restart.txt
cap deploy:rollback      # Rolls back to a previous version and restarts.
cap deploy:rollback:code # Rolls back to the previously deployed version.
cap deploy:setup         # Prepares one or more servers for deployment.
cap deploy:start         # start task is a no-op with mod_rails
cap deploy:stop          # stop task is a no-op with mod_rails
cap deploy:symlink       # Updates the symlink to the most recently deployed ...
cap deploy:update        # Copies your project and updates the symlink.
cap deploy:update_code   # Copies your project to the remote servers.
cap deploy:upload        # Copy files to the currently deployed version.
cap deploy:web:disable   # Present a maintenance page to visitors.
cap deploy:web:enable    # Makes the application web-accessible again.
cap invoke               # Invoke a single command on the remote servers.
cap shell                # Begin an interactive Capistrano session.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2010/07/setting-up-deployment-for-rails-using-capistrano-apache-with-passenger-and-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

