railsをproductionモードで実行する

Ruby on Rails

【Rails】railsをproductionモードで実行する

結論

--environmentオプションを使用します。

$ rails server --environment production

こんな時に使う

Railsアプリを作成して、よしサーバーにデプロイしようという時
デプロイ前に、ローカル環境のproductionモードで
動作確認したい時があります。

そんな時は、--environmentオプションを使用します。

$ rails server --environment production

実行してみます。

$ rails server --environment production

=> Booting Puma
=> Rails 5.2.4.2 application starting in production
=> Run `rails server -h` for more startup options
[28766] Puma starting in cluster mode...
[28766] * Version 3.12.4 (ruby 2.5.1-p57), codename: Llamas in Pajamas
[28766] * Min threads: 5, max threads: 5
[28766] * Environment: production
[28766] * Process workers: 2
[28766] * Preloading application
[28766] * Listening on tcp://0.0.0.0:3000
[28766] Use Ctrl-C to stop
[28766] - Worker 0 (pid: 28780) booted, phase: 0
[28766] - Worker 1 (pid: 28781) booted, phase: 0

こんな感じで、productionモードで起動ができます!
この状態でデプロイ前の動作確認などをします。

省略できる

また、このオプションは省略することもできます。
こんな感じ

$ rails s -e production

普段使う時はこっちの方が短くていいですね。

ピックアップ記事

  1. 【Blender】複数バージョンを簡単に管理できる、BlenderLaunche…
  2. 【Blender】zip版のBlenderをBlender Launcherに移…
  3. 【Rails】modelを作成する
  4. git add -p でファイルの一部をコミットする【Git】
  5. 【Rails】railsでIndex name ‘xxx’…

関連記事

 
  1. Ruby on Rails

    【Rails】文字列からHTMLタグを取り除く方法

    Railsで、HTMLタグを取り除いて文字列を出力したい時があります。…

  2. Ruby on Rails

    【Rails】railsでIndex name ‘xxx’ on table…

    railsで、dbを変更するためにmigrationを実行した際、in…

  3. Ruby on Rails

    【Rails】RSpecのお作法メモ

    RSpecを書く機会が増えてきたので、記法の備忘録として記事にします…

  4. 【Rails】オブジェクトの中身をログに出力する

    Ruby on Rails

    【Rails】オブジェクトの中身をログに出力する

    オブジェクトの中身をデバッグしたりする時に便利出力結果をみやすい形に…

  5. Ruby on Rails

    【Rails】レコードが保存済みか確認するpersisted?メソッド

    レコードが保存されているかどうかでUIの表示を切り替えたり、保存されて…

カレンダー

2026年3月
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

最近の記事

  1. Blender

    【Blender】拡張機能(アドオン)の基本的な使い方
  2. Blender

    起動時の設定をカスタムする【Blender】
  3. gitでファイル変更の一部をコミットする

    git

    git add -p でファイルの一部をコミットする【Git】
  4. Ruby on Rails

    【Rails】findメソッドで連想配列から指定した値を検索する
  5. Blender

    【Blender】アニメーションでポーズを左右反転してコピペしたい時
PAGE TOP