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:
yum update yum -y groupinstall "Development Tools"` yum -y install ntp zlib zlib-devel sqlite-devel httpd mysql-server mysql-devel curl-devel httpd-devel apr-devel apr-util-devel mlocate manlibxml2-devel libxslt-devel libffi-devel readline-devel ntpdate pool.ntp.org /etc/init.d/ntpd start chkconfig ntpd on adduser your_name passwd your_name usermod -G wheel your_name
The last step in this section is to run visudo. Uncomment the line
%wheel ALL=(ALL) NOPASSWD:ALL
Now logout and log back in as your_name.
sudo curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable logout
usermod -G wheel,rvm 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.
type rvm |head -1
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:
Quick note - we’re using 1.9.3 even though 2.0 is available and stable. This is because Passenger stable can not yet use 2.0. Passenger 4.0 can, but is still beta.
rvm install 1.9.3 --with-openssl-dir=/usr
Now let’s set the default version:
rvm use 1.9.3 --default
gem install rake rails
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.
sudo mkdir /etc/httpd/sites-available sudo mkdir /etc/httpd/sites-enabled
We’ll also need a few virtual host specific folders:
sudo mkdir /var/www/application_name sudo mkdir /var/log/httpd/application_name
Now that our folder layout is set, let’s get to the actual configuration files:
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 email@example.com 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.
Now let’s tell Apache where to look for the virtual host definitions:
sudo vi /etc/httpd/conf/httpd.conf
Towards the bottom add:
Save the file.
Two more steps and we’re there.
First link the virtual host definition to sites-enabled
sudo ln -s /etc/httpd/sites-available/application_name.conf /etc/httpd/sites-enabled/application_name.conf
Second, we need to suspend SELinux:
sudo setenforce 0
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.