Need procedure to Deploy Rails 8 App to Rocky Linux 9, NGINX, Puma, Postgresql Production Server

Deploying my Rails 8 app to Production Server, Rocky Linux 9, Postgresql Database, NGINX Web server, Puma Application Server. After searching for a perfect set of instruction to no avail I started putting pieces together base upon what I thought would be required. First this move to Production is on my local Rocky Linux 9 server to learn how to do it. The Rails app is a single page app, very simple again to learn how to deploy to production. Steps so far:

Used rbenv to install ruby 3.4.2 in /usr/local globally. This works well from a global standpoint but not well down the line when I tried to do a bundle install.

Bundler::PermissionError: There was an error while trying to write to /usr/local/rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/cache/benchmark-0.4.0.gem. It is likely that you need to grant write permissions for that path.

So who needs to own Ruby? Where does that get installed? I set up the nginx user to not allow a logon so can’t install it there. Bundle doesn’t like sudo? Haven’t been able to find a good description about what to do here.

Some quest I also haven’t gotten a good explanation about:

secret_key_base - got a complaint about that and tried the command it called for on my server and had problems. So I went to my development site and created the config/credentials/production.key and pushed that to github and started over. but then I was required to do bundle install and that was the end with the gem permissions issues:

Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to /usr/local/rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/cache/benchmark-0.4.0.gem. It is likely that you need to grant write permissions for that path.

Haven’t even figured out the Environment Variable piece or Puma Piece all running under the nginx user.

What I really need is an A-Z procedure which does not seem to exist and the Rails Guides have not been helpful either. If anyone can help or point me to a good procedure I would appreciate it. A Centos server config procedure will also work.

Sometimes when you can’t find something very specifically you might be trying to do the wrong thing.

Most of your problems seem distro specific, e.g. how to install Ruby for the non root user - you also didn’t explain which users you set up.

Maybe your lucky and someone else did a very similar setup and can share it or guide you.

But in general as of late Kamal - GitHub - basecamp/kamal: Deploy web apps anywhere. - is the recommended tool to deploy Rails apps. Prior to that it was mostly PaaS like Heroku & co.

Otherwise there is also a very good course - https://deploymentfromscratch.com - that will walk you through setting everything up yourself.

Thank you for the input, I finally did find a useful site that although not perfect got me where I wanted to go and I now having a working production level site to play with. Here is my path:

The link I used as my basis was: Manually deploy Ruby on Rails 8 application to Linux server

I did alter a few things that didn’t work. If what I did could have been done better I’d like to know.

First I did try the sync process but that got me into trouble with credentials which were excluded and my Mac didn’t like the command so I used github straight up which solved all my problems there. I tried to use the shared directory which also didn’t work so I copied the master_key in the config directory and everything worked. I didn’t know what to do about the Environment Variable so after searching around I found that I could use the credentials.yml.enc and then insert then with <%= Rails.application.credentials.dig(:password) %> Works great and I think better than ENV variables and more secure also. I actually generated a production version with a flag on the edit command. Since I was local and not using ssl I found 2 places needed to be changed to prevent https prefixes but they are actually next to each other. This web site had a pretty complete solution and it was manual which I like. I start manual so that I understand the process then automate from there.