Install Ruby on Rails with Apache and Passenger on CentOS 6

rorlogoIn one of our previous tutorials, we have shown how you can install Ruby on Rails with Nginx and Passenger on a Debian VPS. In this article we will show you how to install Ruby on Rails with Apache and Passenger on a CentOS VPS.

 

 

Firts, lets create a new sudo user

adduser newUser
passwd newUser
usermod -G wheel newUser

 

Run visudo and uncomment the following line

%wheel ALL=(ALL) NOPASSWD:ALL

 

Switch to the new user

su newUser

 

Update the system and install apache

sudo yum -y update 
sudo yum -y install curl curl-devel httpd-devel httpd mod_ssl

 

Install the latest Ruby version using RVM

sudo curl -L https://get.rvm.io | bash -s stable --ruby

To verify everything is done correctly, use the command “ruby -v”.
The output should be similar to the following:

# ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]

 

Install Rails and Passenger

gem install rails passenger

 

Install Passenger for Apache

rvmsudo passenger-install-apache2-module

After finishing, the installer will print a message similar to the following:

LoadModule passenger_module /home/newUser/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.10/buildout/apache2/mod_passenger.so
PassengerRoot /home/newUser/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.10
PassengerDefaultRuby /home/newUser/.rvm/wrappers/ruby-2.0.0-p247/ruby

Create a new passenger.conf file with the lines above.

sudo vim /etc/httpd/conf.d/passenger.conf

 

Create a directory for your rails application

mkdir -p ~/my_rails_app

 

Create a new virtual host for your application.

Open the /etc/httpd/conf/httpd.conf file and uncomment the following line

NameVirtualHost *:80

At the end of the file, add

<VirtualHost *:80>
   ServerName yourdomain.com
   ServerAlias www.yourdomain.com
   DocumentRoot /home/newUser/my_rails_app/public
   <Directory /home/newUser/my_rails_app/public>
      AllowOverride all
      Options -MultiViews
   </Directory>
  ErrorLog /var/log/httpd/my_rails_app_error.log
  CustomLog /var/log/httpd/my_rails_app_access.log common
</VirtualHost>

Restart apache for the changes to take effect

sudo /etc/init.d/httpd restart

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

PS If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Comment