Running Ruby Apps with LSAPI

You are here:
< Back

Running Ruby Apps with LSAPI

In order to maximize the performance of a Rails application, we (LiteSpeed Technologies) developed our own Ruby interface module using our LiteSpeed APIprotocol, also known as LSAPI. LSAPI is a highly optimized IPC protocol between OpenLiteSpeed web server and a standalone process which yields the best possible performance.

Requirements

  • OpenLiteSpeed version 1.4.41+

Setup

Install Ruby Packages

If you haven’t already, please install the Ruby package:
CentOS

yum install ruby ruby-devel rubygems

Ubuntu

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
apt install rbenv libreadline-dev ruby-dev -y
rbenv install 2.5.0
rbenv global 2.5.0

Install rack & ruby-lsapi

The easiest and fastest way to run Ruby apps with LSAPI is to install ruby-lsapi.

gem install rack -v 1.6.11
gem install ruby-lsapi

Set up Context

This example assumes you are using the default document root + URI: /ruby/

Navigate to Web Admin > Virtual Hosts > Context > Add

  • Type = App Server
  • URI = /ruby/
  • Location = /usr/local/lsws/Example/html/ruby/
  • Binary Path = /usr/bin/ruby
  • Application Type = rails

Verification

To verify your setup is correct, create a ruby directory under your document root.

Create a config.ru file with the following content:

app = proc do |env|
    message = "It works!\n"
    version = "Ruby %s\n" % RUBY_VERSION
    response = [message, version].join("\n")
    [200, {"Content-Type" => "text/plain"}, [response]]
end
run app

Visit http://Server_IP:Port/ruby/ in your browser and you should see:

It works!
Ruby x.x.x

How to Set up Rails with Ruby

Install

gem install rails
apt install node.js

Create Project

We will create this project under the Example directory, but you can create it wherever you want to.

rails new demo

Rails Settings

vi demo/config/routes.rb

Input this line before end. Be sure to change /rails to your own context name.

get "/rails", to: "rails/welcome#index"

Change owner

chown -R nobody:nogroup demo

Setup Context

This example assumes you are using the default document root + URI: /rails/

Navigate to Web Admin > Virtual Hosts > Context > Add

  • Type = App Server
  • URI = /rails/
  • Location = /usr/local/lsws/Example/demo/
  • Binary Path = /usr/bin/ruby
  • Application Type = rails

How to verify Rails

Visit http://Server_IP:Port/rails/ in your browser and you should see the following admin page:

Optional Settings

Custom Binary Path

If you want to change the ruby path, you may update the Context and set Binary Path = /usr/ruby.

Custom Startup File Name

If you want to change the default ruby file name from config.ru to example.ru, you may update the Context and set Startup File = example.ru.

Tags: