Sinatra can be used to create web applications on the Ruby platform which can be registered in cPanel’s Application Manager interface (cPanel >> Home >> Software >> Application Manager).
One can even use cPanel’s Terminal interface (cPanel >> Home >> Advanced >> Terminal) in order to perform these steps in cPanel & WHM version 72 and later.
Pre-installation Settings
One needs to make sure that the following EasyApache 4 RPMs
exist on one’s server:
- ea-ruby24-mod_passenger
It is to note that after enabling this module, the system will disable Apache’s mod_userdir module
.
- ea-ruby24-ruby-devel
- ea-apache24-mod_env
In order to install these RPM’s, one has to run the following command:
yum install ea-ruby24-mod_passenger ea-ruby24-ruby-devel ea-apache24-mod_env
Install the Sinatra Gem
To install the Sinatra Gem, one needs to run the following command:
scl enable ea-ruby24 ‘gem install Sinatra’
If one does not wish to use the scl utility
, there are other steps to install the Sinatra Gem.
Steps:
Firstly, one needs to log in to the server as a cPanel user.
Then one can add the following line to one’s shell’s rc
file (for example, /home/user/.bashrc file):
source /opt/cpanel/ea-ruby24/enable
Then one can log out from a terminal session, and log back in again.
One can also create an additional terminal session.
Lastly, one can run the gem install Sinatra
Create the Application’s Directory Path
After the installation of the Sinatra Ruby gem, one can create the application’s directory path which can be relative to one’s home directory, like:
/home/user/frank
Create the Application’s Ruby Files
Steps:
- One needs to change the application’s directory.
- One can create the
rb
file with the help of a text editor. - After that, one needs to add the process one wants the application to execute, as in:
require ‘sinatra/base’ require ‘sinatra/base’ class Fools < Sinatra::Base get ‘/’ do ‘Fools Rush In’ end end
- Then one can create the rb file with the help of a text editor.
- Lastly, one can add the following content to the file:
require File.absolute_path(“app.rb”) run Fools
Register the Application
One can register the application after setting the file permissions. For this, one needs to use UAPI’s PassengerApps::register_application function, or cPanel’s Application Manager interface (cPanel >> Home >> Software >> Application Manager
).
Restart Apache
This step can be optional. The above functions will make the Apache restart but may not necessarily execute immediately.
In order to restart Apache by creating application’s Apache configuration, ne needs to run the following command:
/usr/local/cpanel/scripts/restartsrv_httpd
One can access the application in cPanel’s Application Manager interface (cPanel >> Home >> Software >> Application Manager
) after the restarting of the Apache.
Conclusion
This feature helps a user to create web applications on the Ruby platform with these technical steps.