Setting Up Puma For Rails

Puma is a web server that can be used in Rails Production and Development environments. It is the default server for Rails 5, but if you’re using an earlier version, it needs to be installed.  Although the regular Rails server works fine, Puma is recommended if you’re going to be deploying your app to Heroku.

In the gem file add

gem 'puma'

Create a Procfile in your app folder (must be capitalized), after it’s created it should be listed below the vendor folder in your text editor.

In Procfile add

web: bundle exec puma -C config/puma.rb

In your config folder create a file called puma.rb

In puma.rb add

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
 threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
 threads threads_count, threads_count

preload_app!

rackup DefaultRackup
 port ENV['PORT'] || 3000
 environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
 # Worker specific setup for Rails 4.1+
 # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
 ActiveRecord::Base.establish_connection
 end

In your terminal run bundle install

bundle install

Restart your rails server.

rails s
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s