Install Ruby on Rails with Apache and Passenger on CentOS 6

Status: This OS is no longer supported

This article, “Install Ruby on Rails with Apache and Passenger on CentOS 6,” covers a version of CentOS that reached end of life (EOL). The developing company no longer supports it. As such, we no longer maintain this guide. If you are currently operating a server running CentOS 6, we highly recommend contacting RoseHosting’s fully managed support. They can upgrade or migrate you to a supported version of AlmaLinux.

While this guide may still be helpful as a reference, it may not be compatible with other CentOS releases. Alternatively, the following RoseHosting tutorial outlines how to install Ruby on Rails with PostgreSQL on AlmaLinux 9.

 In one of our previous tutorials, we showed 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.

Step-by-step Guide

First, let’s create a new sudo user

adduser newUser
passwd newUser
usermod -G wheel newUser

Next, 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 confirm everything is set up correctly, run 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.

Next up, 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

Conclusion

Congratulations. You’ve installed Ruby on Rails on CentOS 6. Of course, you don’t have to do any of this yourself if you sign up for one of our Linux VPS Hosting plans. In this case, you can ask our expert Linux admins to install this for you. We are available 24/7 and will attent to all your requests promptly.&amp;amp;amp;lt;/p>

Leave a Comment