Skip to content

Instantly share code, notes, and snippets.

@pdkproitf
Last active December 20, 2021 11:51
Show Gist options
  • Save pdkproitf/ef842e23dc95483c7056df8d9b40daf8 to your computer and use it in GitHub Desktop.
Save pdkproitf/ef842e23dc95483c7056df8d9b40daf8 to your computer and use it in GitHub Desktop.
Run rails production mode

RAILS <= 5.2

  1. Set secret key: To create a secret key, run the following command: bundle exec rake secret Copy the secret key and put it to config/secrets.yml file with the following format:
production:
 secret_key_base: <%=ENV["SECRET_KEY_BASE"]%>
  1. Create credentials
  • Remove the old credentials:rm config/credentials.yml.enc
  • Create a new one: EDITOR='nano --wait' RAILS_ENV=production bin/rails credentials:edit
  1. Create a database: RAILS_ENV=production rails db:create db:migrate db:seed

  2. To precompile your assets, run RAILS_ENV=production rake assets:precompile. This will create a folder public/assetscontains all of your assets.

  3. Run RAILS_ENV=production rails s and you should see your app.

RAILS > 5.2, RAILS 6

  1. Create credentials file:
rails encrypted:edit config/credentials/staging.yml.enc --key config/credentials/staging.key

This going to create a two files:

+ /config/credentials/staging.key
+ /config/credentials/staging.yml.enc
  1. Update credential files:
EDITOR=nano rails encrypted:edit config/credentials/staging.yml.enc --key config/credentials/staging.key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment