<?xml version="1.0" encoding="UTF-8"?>
<post>
  <author-id type="integer">1</author-id>
  <body>MDS Media Group recently moved their site, which is a Ruby on Rails application, to a new dedicated server on Media Temple.  The power and flexibility of the new server is awesome, but having to install and configure everything can prove challenging.  I&#8217;ve successfully deployed several rails apps with fcgi, mongrel, and passenger in production on shared hosting platforms and local development on my Mac, but this was my first attempt on a completely clean slate.  

Media Temple runs CentOS linux on it&#8217;s servers, which is a great system, but lacks an easy to use package manager and doesn&#8217;t have the absolute latest version of Ruby.  

The first step is to &lt;a href=&quot;http://kb.mediatemple.net/questions/807/(dv)+3.5+Tech+Specs+-+Developer%27s+Tools+package+listing&quot; target=&quot;_blank&quot;&gt;install the developer tools&lt;/a&gt; from the account center.  


For the rest of the tutorial, I'm assuming you are logged in via SSH as root and we will be working with &quot;your-domain.com&quot; for this example.

The default installation of CentOS includes Ruby 1.8.5 which is not the latest version.  You must remove the current installation.

&lt;div class=&quot;code&quot;&gt;yum remove ruby&lt;/div&gt;

Next, we need to install Ruby and RubyGems.

&lt;div class=&quot;code&quot;&gt;
cd /opt
wget ftp://ftp.ruby-lang.org:21/pub/ruby/1.8/ruby-1.8.6.tar.gz
tar -zxvf ruby-1.8.6.tar.gz
ln -s ruby-1.8.6 ruby
cd ruby
./configure &amp;&amp; make &amp;&amp; make install
cd ../
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
tar -zxvf rubygems-1.3.1.tgz
cd rubygems-1.3.1
ruby setup.rb
&lt;/div&gt;

Now that the current version of Ruby is installed and RubyGems is available its time to install Rails and Passenger.

&lt;div class=&quot;code&quot;&gt;
gem install rails 
gem install passenger
passenger-install-apache2-module
&lt;/div&gt;

Passenger has a wonderful installer that explains the installation process and what configuration is needed to get your rails application up and running... except it is not entirely accurate for Media Temple&#8217;s setup.  Passenger recommends the following:
&lt;div class=&quot;code&quot;&gt;
Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6
   PassengerRuby /usr/local/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.


--------------------------------------------
&lt;/div&gt;


This part is fine for our setup, but first let&#8217;s backup our apache config file:

&lt;div class=&quot;code&quot;&gt;
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.backup
&lt;/div&gt;

Then to edit your apache configuration file run the following command:

&lt;div class=&quot;code&quot;&gt;
vi /etc/httpd/conf/httpd.conf 
&lt;/div&gt;

And copy the code provided by the Passenger installer to the end of your apache config file (I alway add comments for later reference):

&lt;div class=&quot;code&quot;&gt;
#Passenger for Rails
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /usr/local/bin/ruby
&lt;/div&gt;

The next bit of information that the Passenger installer provides is the settings required for your virtual host file:

&lt;div class=&quot;code&quot;&gt;

Deploying a Ruby on Rails application: an example

Suppose you have a Ruby on Rails application in /somewhere. Add a virtual host
to your Apache configuration file, and set its DocumentRoot to
/somewhere/public, like this:

   &amp;lt;VirtualHost *:80&amp;gt;
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public
   &amp;lt;/VirtualHost&amp;gt;

And that's it! You may also want to check the Users Guide for security and
optimization tips and other useful information:

  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/doc/Users guide.html


&lt;/div&gt;

This is the part that can potentially give you trouble.  The way Media Temple is configured, each domain in your account is located in a vhost directory.  Example:

&lt;div class=&quot;code&quot;&gt;

/var/www/vhosts/your-domain.com

&lt;/div&gt;

Your domain&#8217;s vhost.conf file is located here:

&lt;div class=&quot;code&quot;&gt;

/var/www/vhosts/your-domain.com/conf/vhost.conf

&lt;/div&gt;

If it doesn&#8217;t exist, you must create the file:
(this is also the same command used to edit it)

&lt;div class=&quot;code&quot;&gt;

vi /var/www/vhosts/your-domain.com/conf/vhost.conf
&lt;/div&gt;

Now for the part that differs from Passenger&#8217;s example.  With Media Temple&#8217;s server configuration, the vhost.conf file should not include the &amp;lt;VirtualHost *:80&amp;gt; or &amp;lt;/VirtualHost&amp;gt; directives.  Here is an example of how your vhost.conf should look:

&lt;div class=&quot;code&quot;&gt;

ServerName your-domain.com
ServerAlias www.your-domain.com
DocumentRoot /var/www/vhosts/your-domain.com/path-to/myapp/public
&amp;lt;Directory &amp;quot;/var/www/vhosts/your-domain.com/path-to/myapp/public&amp;quot;&amp;gt;
   Options FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
&amp;lt;/Directory&amp;gt;
RailsBaseURI /

&lt;/div&gt;

Make sure that your app&#8217;s directory and files have the proper owner ie: the domain's user needs to be the owner because passenger runs as the applications owner.  

&lt;div class=&quot;code&quot;&gt;

chown -R your-user:psaserv myapp

&lt;/div&gt;

Now we must remove the default 'httpdocs' directory and create a symbolic link to the application's public folder

&lt;div class=&quot;code&quot;&gt;
mv /var/www/vhosts/your-domain.com/httpdocs /var/www/vhosts/myapp/httpdocs.old
ln -s /var/www/vhosts/your-domain.com/rails/testapp/public /var/www/vhosts/myapp/httpdocs
&lt;/div&gt;

Now restart apache and you are finished!

&lt;div class=&quot;code&quot;&gt;

service httpd restart

&lt;/div&gt;

</body>
  <category-id type="integer">2</category-id>
  <created-at type="datetime">2009-02-12T20:21:15Z</created-at>
  <id type="integer">24</id>
  <status type="integer">1</status>
  <title>Deploying Rails with Passenger on Media Temple</title>
  <updated-at type="datetime">2009-02-18T10:01:51Z</updated-at>
</post>
