Sometimes it’s useful to run a Rails app in production mode locally for testing purposes. This may not always be feasible depending upon the complexity of the project, but when it is, the following steps can be followed.

First is to ensure config/database.yml points to a local database under its production settings. It can be modified to point to the dev environment database temporarily, or specifically a local production database can be created by setting RAILS_ENV=production and invoking the usual Rake db tasks.

In addition to database settings, asset configuration is probably the next most challenging step. With Webpacker, try the following commands (without the comments):

RAILS_ENV=production rails assets:clobber # Needed before the *next* time compile is run
RAILS_ENV=production rails webpacker:compile # When assets have changed

The last environment variable, RAILS_SERVE_STATIC_FILES=1, is referenced in config/environments/production.rb to enable config.public_file_server, which will serve static files from the /public directory.