Deploy rails application with Mina, Nginx and Puma

What is Mina?

Mina is a deployment tool, similar to Capistrano. The major advantage of Mina is its speed. Mina works exceptionally fast because it’s a deploy Bash script generator. It generates an entire procedure as a Bash script, and runs it remotely in the server. It also supports smart command execution, so if you do not change assets (CSS, JS, images), it will not execute assets precompile. The same goes for migrations.

Mina Setup

Let’s take a look at setting up Mina with Puma. First, you’ll need to add Mina and mina-puma in Gemfile, which is located in the development section. Mina recently changed its maintainer; a new repository is here, and it is best to install it from Git.

Add Puma gem to the global section if you are using a Rails version below 5.

Then, install gems and execute the initial Mina command for generating a config/deploy.rb file.

mina init

You can find an example of a Mina 1.0.0 default config here. Click here for the full config in that configuration.

Detailed explanations of the Mina deploy file

By default, Mina will create all folders mentioned in shared_dirs and shared_files. In setup, however, you can add section auto-creation of empty files and fill them later.

After these actions, you are ready to run Mina setup to prepare all necessary file structures at the remote server.

Your deploy section in deploy.rb should look like this:

Puma Setup

Create or fill a puma.rb file in a config folder.

You must point a path to pumactl.sock at activate_control_app. Otherwise, Mina puma:stop and restart will not work.

Fill database.yml and secrets.yml

Go to the shared folder and make sure that you fill these two files.

Setup nginx

Create file myapp.conf in a /nginx/etc/conf.d folder with similar content.

Generate ssh keys

Generate new ssh keys on your server by using that command ssh-keygen. Then, export it to the deploys keys of your github/bitbucket project.

Mission Completed

That’s it. Now you’re ready to deploy your application. Run mina deploy if you have already executed mina setup and wait.


If you have problems on git clone, check that you have exported ssh pub key to your repository, and try to clone the repository directly from the server.

Use Mina puma:start on first launch instead of phased_restart.

Useful Links:

Mina and multi-stages

Tap the ❤ button if you found this article useful!

Any questions or Feedback? Connect via Pixel Point