LoginSignup
11
13

More than 5 years have passed since last update.

dotinstallのHeroku入門で激しくハマった

Last updated at Posted at 2014-08-06

#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

スクリーンショット 2014-08-06 8.20.03.png

  • 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が作成できない

スクリーンショット 2014-08-06 8.33.51.png

$ 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

スクリーンショット 2014-08-06 8.57.52.png

11
13
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
11
13