Launch the Rails app locally in production mode (API Server)

Here are the steps to get Rails to start locally in production mode.

This time, only the steps required to use Rails as an API server.

environment

procedure

database.yml settings

To check the operation, you can set the same settings as when you started in development mode except for the DB name. If it is the same as when rails new, it should look like this.

database.yml


default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  host: localhost

development:
  <<: *default
  database: my_app_development

test:
  <<: *default
  database: my_app_test

production:
  <<: *default
  database: my_app_production

DB setup

% RAILS_ENV=production bundle exec rails db:setup
Created database 'my_app_production'

Just db: setup should do db: create, db: migrate, db: seed.

Start the server in production mode

$ bundle exec rails s -e production

If you can confirm access with curl etc., it's OK.

The application that I confirmed to work had sidekiq installed, so I accessed / sidekiq, but it worked fine.

in conclusion

Did it work so easily, even though it's just an API server?

I wonder if it's easier than it used to be.

Recommended Posts

Launch the Rails app locally in production mode (API Server)
[Rails] Use cookies in API mode
[Rails] Reset the database in the production environment
Nuxt.js × Create an application in Rails API mode
500 Internal Server Error occurs in Rails production environment
Rails (API mode) x React x TypeScript simple Todo app
[Error] The app is not displayed in the production environment
[Rails] How to reset the database in production environment (Capistrano version)
About the symbol <%%> in Rails erb
Create a new app in Rails
Parsing the COTOHA API in Java
Hit the Docker API in Rust
How to return Rails API mode to Rails
[Rails] About the error that the image is not displayed in the production environment
[Rails] How to apply the CSS used in the main app with Administrate
Change the save destination of the image to S3 in the Rails app. Part 2
Change the default timezone for the rails app
Try using the Stream API in Java
Call the Windows Notification API in Java
The identity of params [: id] in rails
Try using the Rails API (zip code)
Rails refactoring story learned in the field
Rails API server environment construction using docker-compose
Specify home view in rails app [root]
Rails server cannot be started in Cloud9
Rails6: Extract the image in Action Text
Display the background image in the production environment