Configuring a Ruby on Rails application on a shared hosting account
Learn how to use the Setup Ruby App feature in cPanel to configure and run a Ruby on Rails application in a shared hosting environment.
This article describes how to use the Setup Ruby App feature in cPanel to configure and run a Ruby on Rails application in a shared hosting environment.
Step 1: Create the application in cPanel
First, you must create the application in cPanel using the Setup Ruby App feature. To do this, follow these steps:
-
Log in to cPanel.
Note
If you do not know how to log in to your cPanel account, please see this article.
-
Open the Ruby App tool:
-
If you are using the Jupiter theme, on the Tools page, in the Software section, click Setup Ruby App:
-
If you are using the Paper Lantern theme, in the SOFTWARE section of the cPanel home page, click Setup Ruby App:
-
-
On the Setup Ruby App page, under Setup New Application, do the following:
-
In the Ruby version list box, select 2.5.
Important
Ruby 2.6 introduces dependency conflicts and currently does not work with Rails on a shared hosting account. You must use Ruby version 2.5 instead.
-
In the App Directory text box, type the name of the directory where you want to store the application files. For example, type
railsapp
. -
In the App Domain/URI list box, select the domain you want to use, and then type the URI in the text box.
-
-
Click Setup. cPanel creates the application.
-
Under Existing applications, locate the application (for example, railsapp ).
-
In the modules row, click show.
-
In the text box next to Add, type
rails
and then click Add. -
At the bottom of the application section, click Update. cPanel installs the Rails module.
-
Next to Command for entering to virtual environment, copy the entire command that begins with source. You will use this command in the next procedure.
Step 2: Configure the application from the command line
At this point you have created the Ruby on Rails environment in cPanel. Now you are ready to create and configure the Rails application itself. To do this, follow these steps:
-
Log in to your account using SSH.
-
At the command prompt, paste the command you copied in step 9 of the previous procedure. This command activates the Ruby virtual environment.
Tip
To confirm the virtual environment is active after you run the source command, check that the Bash prompt starts with the application name and Ruby version number. For example:
(railsapp:2.5)example@mi3-ss21 [~]#
-
Type the following command:
unset XDG_RUNTIME_DIR
Important
You must run this command every time after you activate the virtual environment. Alternatively, you can combine this command with the command above to activate the virtual environment. For example:
source /home/username/rubyvenv/railsapp/2.5/bin/activate && unset XDG_RUNTIME_DIR
-
To back up the config.ru file, type the following commands. Replace railsapp with the name of your own application directory:
cd ~/railsapp mv config.ru config.ru.bak
-
To create the Rails application, type the following command. Replace railsapp with the name of your own application directory:
rails new ~/railsapp
-
To add a default route, open the config/routes.rb file in your preferred text editor. Add the following line after the Rails.application.routes.draw do line:
root 'rails/welcome#index'
-
Save your changes to the config/routes.rb file.
-
In cPanel, restart the application. On the Setup Ruby App page, under Existing applications, locate the application, and then click Restart.
-
Open the application URI in a web browser, and you should see the Yay! You're on Rails page. You can now add controllers and other components to your Rails application.
Troubleshooting
If the Ruby on Rails application does not work correctly, you can check the application log files for errors. The application log files are located in the log directory (for example, ~/railsapp/log ). There are separate log files for each environment:
-
production.log for the production environment.
-
development.log for the development environment.
If you need further assistance, please open a support ticket at https://my.hosting.com.
More Information
-
To view the official Rails getting started guide, please visit https://guides.rubyonrails.org/getting_started.html.
-
To view the official Rails API documentation, please visit https://api.rubyonrails.org.
Related Articles
Updated 3 days ago