Last Updated: February 25, 2016
·
4.866K
· toymachiner62

How to setup rails app on a mediatemple (dv)

Setting up your first rails app on a mediatemple (dv) was a very daunting task for me, but i've done it a bunch of times now so i will explain the steps to getting your app up quickly.

I personally use capistrano, but that can be a challenge of its own so i'll skip that part for now.

Prerequisites

Have root access to your (dv)
Add domain to your mediatemple control panel
Add domain to your plesk panel
Create db and db user in plesk

Step 1 - Install RVM and Ruby

If you don't have ruby installed on your machine (or even if you do, but want to use RVM), you need to install it.

I use RVM and to install RVM, install a version of ruby, and set it as the default, run these commands:

$ \curl -L https://get.rvm.io | bash -s stable --rails $ rvm install 1.9.3 $ rvm use 1.9.3 --default

Step 2 - Setup a gemset for your project

Navigate to your sites directory
$ cd /var/www/vhosts/mysite.com

Create a gemset for your project:
$ rvm gemset create mysite $ rvm gemset use mysite

Step 3 - Install passenger

Install the passenger gem
$ gem install passenger

Step 4 - Configure apache

Create a vhost.conf file for your project
$ cd /var/www/vhosts/mysite.com/conf $ nano vhost.conf

Here's the settings I use in my vhost.conf file. You may want to change some of the settings for your specific app

ServerName mysite.com
ServerAlias mysite.com
DocumentRoot /var/www/vhosts/mysite.com/httpdocs/public
PassengerAppRoot /var/www/vhosts/mysite.com/httpdocs

<Directory "/var/www/vhosts/mysite.com/httpdocs/public">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>

RailsEnv production
RailsBaseURI /
PassengerMaxPoolSize 1
PassengerMaxInstancesPerApp 1
PassengerPoolIdleTime 30

Now you need to run a command to reconfigure apache to look at your vhost.conf file:

$ /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain mysite.com

Step 5 - Move rails project files to server and run bundle and rake

Now you need to move your rails project files to your server. If you're not using capistrano, just use FTP and put them in /var/www/vhosts/mysite.com/httpdocs

Now you need to run bundle install and your rake db:migrate commands. Note though that it may be necessary to use bundle exec and RAILS_ENV

$ bundle install $ bundle exec rake db:migrate RAILS_ENV=production

Step 6 - Enjoy

Hit your url in a browser, crack a bud light, and tell your self "Damn i'm good"

4 Responses
Add your response

Seriously man, you are a god. Got a client to agree to using rails and got to the deploying stage and I was like WHAT THE HELL IS GOING ON.

I normally develop in .NET MVC at work and it's a lot easier, so this tutorial is amazing!

Thanks dude!

over 1 year ago ·

Actually, getting this error, any ideas?

2013-09-06T21:07:44-07:00 ERR (3): Apache config (13785268630.78534100) generation failed: Syntax error on line 4 of /var/www/vhosts/[mydomainname]/conf/vhost.conf:
Invalid command 'PassengerAppRoot', perhaps misspelled or defined by a module not included in the server configuration

Syntax error on line 4 of /var/www/vhosts/[mydomainname]/conf/vhost.conf:
Invalid command 'PassengerAppRoot', perhaps misspelled or defined by a module not included in the server configuration

My VHOST.conf is the same as your tutorial, with the domain name changed....

Any ideas?

over 1 year ago ·

I'm not 100% sure that line is even necessary. Try commenting it out and see if your app works. If not, can you copy and paste your entire vhost.conf file to a pastebin and put the link here so i can take a look at it?

over 1 year ago ·

Thanks a lot! One thing I'll add is that if you want your site secured via an SSL certificate, the set up is pretty much the same, but you'll also need to create a vhost_ssl.conf file, in the same place as vhost.conf (it can basically be a copy, with the same contents).

You'll need to run

/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain mysite.com

again, and restart apache, after creating vhost_ssl.conf

over 1 year ago ·