After spending 7 painstaking hours attempting to get Rails + Passenger (mod_rails) going on a (dv) VPS I have, I decided to post up my procedure for getting this going (sans the hours spent researching).
This setup wont change much of your current setup, whether it’s a new (dv) or one you’ve been using for a while. I personally preformed the following on my 1 month old, fairly untouched, v3.5 (dv).
Prerequisites
Developer Tools – Install Guide.
yum remove ruby
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 && make && 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
gem install rails (unless already installed)
gem install passenger
passenger-install-apache2-module
Step 5: chown -R {your_domains_username} {your_rails_app}
service httpd restart
Your Done!
Tips: Ensure your app’s directory is owned by it’s domain’s respective owner, since passenger runs as the apps owner.
Greg December 7th, 2008
Hi,
I was wondering if you would be willing to assist me with understanding some steps in your tutorial. I have a MediaTemple(dv) 3.5 that I just got setup the other day.
Step 5: chown -R {your_rails_app} {your_domains_username}
Step 6: service httpd restart
Tips: Ensure your app’s directory is owned by it’s domain’s respective owner, since passenger runs as the apps owner.
Perhaps I am just unsure because I am ignorant or because I am new to rails/passenger, but I had the following questions:
1) What does Step 5 accomplish? 2) What does {your_rails_app} represent in relation to my (dv) setup? (I created an app called testapp) 3) What does {your_domains_username} represent in relation to my (dv) setup? (I’ve been SSHing with root to get rails setup) 4) I do not quite understand your tip. Perhaps it’s late, but any clarification would be incredible! 5) In Step 4, this is what I added to the bottom of /etc/httpd/conf/httpd.conf:
- Passenger
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.5/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.5
PassengerRuby /usr/local/bin/ruby
# Passenger Fitness VirtualHost <virtualhost> ServerName testapp.mydomain.com DocumentRoot /var/www/vhosts/mydomain.com/subdomains/testapp/rails/testapp </virtualhost>6) Please help! ;)
Thank you in advance for your expertise. I’m really wanting to learn and it seems the popular method of deploying a Rails app is using Passenger!
Thanks,
G
Eric A. December 8th, 2008
Hi Greg,
To answer your questions…
1. Since passenger’s processes run as whatever users owns your rails application directory, it’s good to ensure that’s the case. Especially if you use capistrano for deployment and it doesn’t reset ownership unless you code it to. Passenger will not run if the rails app directory is owned by a user such as “root”.
2 & 3 & 4: For example; if the username for the website your setting up is “testuser” and your rails app is “testapp”, you will want “testuser” to be the owner of the “testapp” directoy. Thus, making your command as so: chown -R testuser testapp.
5. You’re httpd.conf looks good, however, you’ll want to edit the line:
DocumentRoot /var/www/vhosts/mydomain.com/subdomains/testapp/rails/testapp
and change to…
DocumentRoot /var/www/vhosts/mydomain.com/subdomains/testapp/rails/testapp/public
Let me know how that goes.
- Eric
Jay December 16th, 2008
wget ftp://ftp.ruby-lang.org:21//pub/ruby/1.8/ruby-1.8.6.tar.gz
Eric A. December 17th, 2008
@jay
Thanks for the updated link. The article now includes it.
Paul H. January 1st, 2009
Hello,
One further clarification. Does it matter if our rails app has been created, when we do the chown -R?
Thanks.
Eric A. January 1st, 2009
@Paul
Not at all. You may actually want to run the chown command after your rails app is on the server, unless you’ve actually created it on the server or deployed it to the server using the correct user account.
Paul H. January 1st, 2009
Hi Eric,
Thanks. I am pretty much a novice at Linux. I tried creating a rails app in my new domain, but permission was denied. I think I must have to login with root privileges to do it. Or is there another work around? As the root level how do I navigate to my user ‘myuserid’.
Eric A. January 2nd, 2009
@Paul
You should be able to run rails commands from your user’s bash. However, if your main users folder is somehow owned by root and not it’s own userid, that could cause the issue.
What you’ll probably want to do is; SSH in as root and ensure your users httpdocs directory (located in /var/www/vhosts/<yourdomain> is owned by your user’s userid. You can find out who the owner is by running the “ls -la” command. If the owner is incorrect, run “chown -R <yourusername> httpdocs”.
Let me know if that helps at all!
Paul H. January 2nd, 2009
Hi Again Eric,
Thanks for your help again! Okay, so I think I successfully set up the document root and load modules. I checked the owner of httpdocs and it was owned by my userid.
I ran this command successfully. service httpd restart
When I went to my domain.mydomain.com, rather than seeing the rails app page, I see the index.html page in httpdocs.
Here is my setup<virtualhost>
ServerName subdomain.mydomain.com
DocumentRoot /var/www/vhosts/mydomain.com/subdomains/subdomain/ui/public
</virtualhost>
I also ran the chown command.
I think I’m getting close.
Paul
Paul H January 7th, 2009
Hi Eric,
Just an update. After messing with this for 8 hours, I finally got the site up. I had to put my virtual host info in a file off of my subdomain.
domain/subdomains/mysubdomain/conf/vhost.conf
In that file I placed the document root info
ServerName subdomain.mydomain.com DocumentRoot /var/www/vhosts/mydomain.com/subdomains/mysubdomain/httpdocs/myrailsapp/public
without the <VirtualHost tag.
And then had to create my rails app in the httpdocs folder.
Thanks for your help.
Paul
Stephen Korecky February 3rd, 2009
For the life of me, I can’t see to get this to work… This is what I have in my httpd.conf file: <virtualhost> ServerName test.stephenkorecky.com DocumentRoot /var/www/vhosts/stephenkorecky.com/subdomains/test/httpdocs/public </virtualhost>
Also the command service httpd restart doesn’t work, I have to use /etc/init.d/httpd restart
I could use some input on this, thanks for any help!
Eric A. February 11th, 2009
@Stephen
Are you getting any specific error messages? Have a look in the apache error_log and rails log and post your findings here. I’ll try my best to help.
Thanks!
Stephen Korecky February 25th, 2009
@Eric Sorry for the long delay, but yes as you saw by my blog I was finally able to get it running. The problem like @paul pointed out seems to be with setting up a vhost.conf in your domain folder, since it’s needed by plesk to find your site root… Stupid plesk.
Anyways, the really confusing part was when I loaded my basic default rails app and clicked on “About this application” link, it would display an error page, but regardless passenger-status told me my apps was running, so I created a new page with a time stamp in ruby and it displayed, so it turns out it was working!
So part of it was Plesk, and the other part was Rails acting up, and with my not so strong knowledge of Production rails, it was hard for me to do, but now I have finally got it working! Thanks!
theRemix March 13th, 2009
last line of Step 2. # ruby setup.rb ruby was not yet in my path, -bash: /usr/bin/ruby: No such file or directory
so i had to run it like: # ../ruby/ruby setup.rb which worked for me
Michael May 25th, 2009
I believe I followed the instructions correctly, but when I go to my domain and click on my application’s environment settings, I get the following:
“We’re sorry, but something went wrong.
We’ve been notified about this issue and we’ll take a look at it shortly.”
I’m not sure what’s going on, but if you have any ideas as to how to get this working I’d really appreciate it!
Thanks!
Phill June 8th, 2009
The easy solution that takes much less time than 7 hours, dump MT. That’s what I had to do for a client. Read the knowledge base and notice that you can use only MT versions of gems. I don’t know about you guys, but I don’t have 7 hours to waste, only to find out that I can’t run my app because the MT version of the gem sucks ars.
My 2 cents, if you care about your work, your clients, and have a bit of admin know how, just lease a dedicated server with a good provider that has a firewall and support. $40 or 60 vs $100 to have a dedicated machine with 2G of REAL RAM – enough to host most of my clients sites. Pickup a Linux admin book and for the love of God don’t install Plesk!!!!!
Thanks and good luck.
Cindy July 3rd, 2009
I am currently battling MT’s dv setup and finding all kinds of pain. I am working on an existing app and attempting to deploy updates. The original application did not use Capistrano. I would like to use that now. We thought that we could put the files up in a separate directory and then switch to the new code base by changing the Apache config file.
The problem is that when we used Cap to put up the new code, it broke the current site and to restart it we had to reinstall gems.
First question is, should I take a different approach to put up the code updates?
Second question I have is what am I doing wrong that disables the current live application?
I’d like to dump MT, but I’m not sure I can do that right now.
Thanks!!!
Eric A. July 17th, 2009
@Phill
No question dumping MT is a viable option. But I can however, see how an extra $40-60 for a dedicated box could be a stretch for most, not including the labors of managing a dedicated box.
@Cindy
That seems like a very strange issue. I’m afraid I can’t be of much help without some more details of your Capistrano deploy recipe. But, I can definitely say that shouldn’t be happening by default. Perhaps capistrano is installing your app-specific gems on your VPS upon deployment?
Join The Discussion