How to Create a Sinatra Ruby Application
Last modified: 2024 February 22
Overview
- Because WebPros International, LLC doesn’t develop or ship Sinatra Ruby applications, cPanel Technical Support can’t help you install them. We aren’t responsible for any data loss.
- We recommend that only experienced system administrators perform these steps.
- Before you begin, your hosting provider must enable the feature and install EasyApache 4 RPMs.
This document describes how to install a Sinatra web application. You can use Sinatra to quickly create web applications on the Ruby platform. Then, you can register them in cPanel’s Application Manager interface (cPanel » Home » Software » Application Manager).
-
We recommend that you perform the steps in this document via the command line as a cPanel user unless the step specifies otherwise.
-
You can also use cPanel’s Terminal interface (cPanel » Home » Advanced » Terminal).
-
To use this feature, the cPanel account must possess compiler access in WHM’s Compiler Access interface (WHM » Home » Security Center » Compiler Access). If the account does not possess compiler access, the system will return an error similar to the following message:
make: execvp: gcc: Permission deniedFor more information, read Sinatra’s documentation.
Install Sinatra
Pre-installation settings
Before you begin, make certain that the following EasyApache 4 RPMs exist on your server:
-
ea-ruby27-mod_passengerNote:If you enable this module, the system will disable Apache’s
mod_userdirmodule. -
ea-ruby27-ruby-devel -
ea-apache24-mod_envNote:The
ea-apache24-mod_envmodule allows you to add environment variables when you register your application. For more information about environment variables, read our Application Manager documentation.
If you need to install these RPMs, use WHM’s EasyApache 4 interface (WHM » Home » Software » EasyApache 4) or run the following command as the root user:
yum install ea-ruby27-mod_passenger ea-ruby27-ruby-devel ea-apache24-mod_envInstall the sinatra gem
To install the sinatra Ruby gem, run the following command:
scl enable ea-ruby27 'gem install sinatra'If you do not wish to use the scl utility, perform the following steps to install the sinatra Ruby gem:
-
Log in to the server as a cPanel user.
-
Add the following line to the
rcfile (for example, the/home/user/.bashrcfile):
source /opt/cpanel/ea-ruby27/enable-
Log out and then log back in.
-
Run the
gem install sinatracommand.
Create the application directory path
After you install the sinatra Ruby gem, create the application’s directory path, relative to your home directory.
For example:
/home/username/applicationCreate the application’s Ruby files
After you create the application’s directory path, add the Ruby application file. To do this, perform the following steps:
-
Navigate to the application’s directory
-
Create the
app.rbfile and add the code for the application to execute. For example:For more information about how to add processes to the1 2 3 4 5 6 7require 'sinatra/base' class Fools < Sinatra::Base get '/' do 'Fools Rush In' end endapp.rbfile, read Sinatra’s documentation. -
Create the
config.rufile with the following content:1 2 3require File.absolute_path("app.rb") run Fools
Register the application
After you set the file permissions, register the application. To do this, use either of the following methods:
- Use cPanel’s Application Manager interface (cPanel » Home » Software » Application Manager).
- Call UAPI’s
PassengerApps::register_applicationfunction.
Restart apache
- This step is optional. UAPI’s
register_applicationfunction performs an Apache restart, but may not execute immediately. - For more information, read ourĀ Modify Apache Virtual Hosts with Include Files documentation.
After you create the application’s Apache configuration, restart Apache. To do this, run the following command as the root user:
/usr/local/cpanel/scripts/restartsrv_httpdAfter Apache restarts, you can access the application in cPanel’s Application Manager interface (cPanel » Home » Software » Application Manager).