1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

.envファイルとは

Posted at

昨日は、「.env」ファイルを使って秘密鍵やアクセスキーを管理する方法を
投稿しましたが、「.env」ファイルも気になったので今回記事を書くことを決めました

概要

UNIX系のOSで使えるコマンド「env」の本体ファイル

.envファイルを使って開発環境と本番環境を切り替えたり、
DBなどの接続情報の変更を行うことができる

例えば開発環境ではsqlite、
本番環境ではmysqlのDBに接続といった変更が可能となる

.envファイルの中身は複数のキーと値のペアで記述されている

「env」コマンドとは

コンピュータに対する命令の1つ
環境変数を設定してコマンドを実行する時に使うコマンド

ルール

空行は無視される
・「#」で始まる行はコメントだとみなされる
・値にスペースを含んでいてもクォーテーションで囲む必要はない
シングルクォートやダブルクォートで囲んでもいい
・値の記載を省略した場合は空文字になる
(例: KEY1= とすると、{ KEY1: '' } になる)
・キーや値の前後の空白は削除される。削除したくない場合は、シングルクォートかダブルクォートで値を囲む必要がある
(例: KEY1=' AAA ')
・エンコーディング形式は「utf8」で保存する
→dotenv.configのオプションで変更できる

参考記事

https://railsguides.jp/configuring.html
https://wa3.i-3-i.info/word14462.html
https://wa3.i-3-i.info/word11209.html
https://reffect.co.jp/laravel/env-file-basic-understanding

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?