Postgresqlの設定からRailsアプリケーションをherokuで動かすまで①
Macの開発環境において、簡単なRailsアプリケーションをheroku上で動かすまでの手順をメモとして残します。 説明の大まかな流れは以下の通りです。
- herokuで利用するpostgresqlのローカルでのインストールと設定
- herokuのインストールと設定
- railsアプリケーションの生成とherokuへのデプロイ
Postgresqlのインストールと初期設定
1. インストール
brew install postgresql
2. 設定ファイルの変更
echo 'export PGDATA="/usr/local/var/postgres"' >> ~/.bash_profile source ~/.bash_profile
3. 起動
postgres -D /usr/local/var/postgres
4. Password設定
psql postgres // ログイン postgres=# \password (パスワードの入力) \q // ログアウト
5. confファイルの変更
- /usr/local/var/postgres/pg_hba.confを以下の通り変更
// 変更前 local all all trust host all all 127.0.0.1/32 trust local all all ::1/128 trust // 変更後 local all all md5 host all all 127.0.0.1/32 md5 local all all ::1/128 md5
6. 再起動
- 停止: Ctrl + Cでストップ
- 起動
postgres -D /usrl/local/var/postgres
7. ログイン
psql -d postgre
psqlオプション
- -d: データベース名 (省略可、省略した場合はログインユーザ名が指定される)
- -U: ユーザ名 (省略可、 省略した場合はログインユーザ名が指定される)
- h: ホスト名 (省略可、省略した場合はlocalhostが指定される)
次の記事に関して
次の記事では、Postgresqlでユーザ作成+DB作成について説明します。