#05 Railsアプリケーションを作ろう | Heroku入門 - プログラミングならドットインストール
herokuコマンド
herokuコマンドをインストールできない
Downloadするため https://toolbelt.heroku.com にアクセスするもリダイレクトループでページが表示されなかった。
仕方ないので手動でインストール
wget https://toolbelt.heroku.com/install.sh
sh install.sh
echo export PATH=/usr/local/heroku/bin:\$PATH >> ~/.zshrc
source ~/.zshrc
herokuにログイン
heroku login
Enter your Heroku credentials.
Email: tukiyo3@gmail.com
Password (typing will be hidden):
Found the following SSH public keys:
1) id_boot2docker.pub
2) id_rsa.pub
Which would you like to use with your Heroku account? 2
Uploading SSH public key /Users/owner/.ssh/id_rsa.pub... done
Authentication successful.
rails
rails new mymemo -d postgresql
cd mymemo
Gemfile
- # gem 'therubyracer', platforms: :ruby
+ gem 'therubyracer', platforms: :ruby
postgresql
pg_configがない
- postgresql-devel に pg_configが含まれています。
yum install -y postgresql-server postgresql-devel
postgresqlが起動できない
- initdbするようにメッセージが表示されているので従う。
service postgresql initdb
dockerでpostgresql起動時にエラーが出る
- 無視
service postgresql start
Starting postgresql service: /etc/init.d/postgresql: line 114: echo: write error: Permission denied
rails sでpostgresqlに接続できいない
rails s
- http://localhost:3000 にアクセスすると以下エラー
- postgresqlに接続できていないことだと思うので以下実施
postgresの勉強してみた。
いくつか事前知識
-
su - postgres
してからpsql
でpostgresに接続できる。 -
\l
データベース一覧表示 -
\du
ユーザ一覧表示 -
\h
SQLコマンド一覧表示。わりと役立つ -
\q
quit - postgresユーザにて
createuser mymemo
でアカウント作成できる。 -
use database
に対応するのは\connect DBNAME
※ 以下は今回する必要ない。
su - postgres
psql
create role mymemo with login;
create user mymemo with password 'mymemo';
create database mymemo with owner mymemo;
\l
\q
- パスワードの変更は
alter user mymemo with password 'newpass'
$ psql -U username でpostgresに接続ができない
$ psql -U mymemo
psql: FATAL: Ident authentication failed for user "mymemo"
/var/lib/pgsql/data/pg_hba.conf
- local all all ident
+ local all all trust
service postgresql restart
psql -U mymemo
- 接続できることを確認。
rootでpsql接続する場合
-
psql -U postgres
するのが流儀っぽいが、psql
だけで接続したい場合。-
psql
コマンドだけだと、usernameとdatabase名に現在ログイン中のユーザ名が使われる。
-
$ createuser root
Shall the new role be a superuser? (y/n) y
databaseが作成できない
$ bin/rake db:create db:migrate
PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "mymemo_development" ENCODING = 'unicode'
config/databases.yml
development:
<<: *default
database: mymemo_development
+ template: template0
ようやくrails sに成功
rails s