2013-03-23: This is an updated version of a post I wrote a little over a year ago. There have been some security issues with Rails in that time, and some updated versions of nearly all the software involved.
Installing RVM Multi-user on CentOS can be a bit tricky. Here's my documentation - mostly so I remember, but hopefully it helps someone else as well.
A quick note - the people behind RVM are clear that tutorials outside their siteare not supported. They're not discouraged, but they won't support them. Pretty reasonable. These directions worked for me, but you should understand what you're doing before following directions on the internet.
My install was for Ruby 1.9.3 and Rails 3.2.13 on CentOS 6.4 x86_64 installed on a VMware Fusion virtual machine. As this was for a local devel environment I did a few things I wouldn't suggest doing on a production or publicly available site. I want to use Apache and a local MySQL instance, so I'll be installing those as well.
Ok, with that out of the way:
First, as root:
Now logout and log back in as your_name.
Now we're getting somewhere. RVM is installed and we're about ready to install ruby. Let's do a couple of sanity checks first.
Log in as your_name.
As a multi-site install RVM should have been installed to /usr/local/rvm. Let's do some sanity checks.
rvm is a function
OK, we've successfully installed RVM. Now let's install Ruby. We'll include an openssl directive so we can install Passenger in a bit. Still as your_name:
Now let's set the default version:
rvm use 1.9.3 --default
Now rake and rails are installed. Let's install passenger (and a gem for database connectivity).
gem install mysql2 passenger
OK, now to set up passenger for Apache:
Pay attention to the paths that the install script gives you at the end. Copy them to a text file somewhere - we'll need them in a bit.
Now let's configure Apache.
I like the way Ubuntu lays out the Apache config - especially virtual hosts - so we'll mimic that here.
We'll also need a few virtual host specific folders:
First up, passenger. Let's create a passenger.conf file and paste in the paths we saved previously:
sudo vi /etc/httpd/conf.d/passenger.conf
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19/ext/apache2/mod_passenger.so PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19 PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p392/ruby
Save the file. This will load the passenger module when Apache starts.
Next let's set up the virtual hosts:
sudo vi /etc/httpd/sites-available/application_name.conf
<VirtualHost*:80> ServerAdmin firstname.lastname@example.org DocumentRoot /var/www/application_name/public ServerName yourservername ErrorLog /var/log/httpd/application_name/error.log CustomLog /var/log/httpd/application_name/access.log common <VirtualHost>
It's important to note we're pointing the DocumentRoot to /public of your application.
Towards the bottom add:
Save the file.
Two more steps and we're there.
I would absouletly, positively run SELinux on a publicly facing website. Spend some time to learn to configure it - it's not nearly as scary as it looks at first.
Go ahead and deploy your application to /var/www/application_name. Finally, start apache to make sure it runs sudo service httpd start.
That's it. You should be able to visit your site at http://yourservername.