Complete Guide to Setting Up Ruby on Rails 3 on WHM (CentOS)
Running Ruby on Rails 3 on a WHM (Web Host Manager) server with CentOS involves several steps, including installing Ruby, setting up Rails, configuring Apache or Nginx, and integrating with cPanel if necessary. Here’s a step-by-step guide to get you started:
Prerequisites
- A server running CentOS with WHM/cPanel installed.
- Root access to the server.
Step-by-Step Guide
- Access Your Server:
Connect to your server via SSH.
ssh root@your_server_ip
- Install Required Dependencies:
Update your package list and install necessary dependencies.
yum update -y
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel
- Install RVM (Ruby Version Manager):
RVM makes it easy to install and manage different Ruby versions.
curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
Add your user to the RVM group:
usermod -a -G rvm $USER
- Install Ruby:
Use RVM to install Ruby 1.9.3, which is compatible with Rails 3.
rvm install 1.9.3
rvm use 1.9.3 --default
- Install Rails:
Install Rails 3 using the gem command.
gem install rails -v 3.2.22
- Set Up Your Rails Application:
Create a new Rails application or move an existing one to your server.
rails new myapp -v 3.2.22
cd myapp
If you have an existing application, just move it to your server.
- Install Passenger:
Passenger is a web and application server for Ruby, Python, and Node.js. It integrates well with Apache and Nginx.
gem install passenger
passenger-install-apache2-module
Follow the instructions provided by the Passenger installer to configure Apache.
- Configure Apache with Passenger:
Edit your Apache configuration file to include Passenger settings.
nano /etc/httpd/conf/httpd.conf
Add the following lines at the end of the file:
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-5.0.30/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-5.0.30
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-1.9.3-p551/ruby
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /path/to/your/app/public
<Directory /path/to/your/app/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
Replace /path/to/your/app
with the path to your Rails application and yourdomain.com
with your domain.
- Restart Apache:
Restart Apache to apply the changes.
service httpd restart
- Integrate with cPanel (Optional):
If you need to integrate Rails with cPanel, you may need to manually configure each domain or subdomain through cPanel’s interface to point to your Rails application. This typically involves setting up the domain, creating the appropriate directory structure, and configuring the Apache virtual hosts as described above.
Additional Tips
- Database Configuration: Ensure your database (MySQL, PostgreSQL, etc.) is configured correctly in your
config/database.yml
file. - Environment Variables: Set any necessary environment variables in your
.bashrc
or.bash_profile
. - SSL Configuration: If your application requires SSL, configure your virtual host for HTTPS.
By following these steps, you should be able to set up and run a Ruby on Rails 3 application on a WHM/cPanel server with CentOS. If you encounter any issues, refer to the logs and error messages for troubleshooting.