Herokuを使っているプロジェクトを手伝ったことはあるのですが、自社プロジェクトではAWSオンリーでやっていたのであまり触っていませんでした。
本番環境だけでなく検証環境もAWSで構築していたのですが、そこってAWS必要ないんじゃね?っていうところをきっかけに。
Mac OSX 10.9でやります。
Getting Started!
まずは公式へ。
さっさとSignupします。
https://www.heroku.com/
Signup、認証が完了すると下記のような画面に連れて行かれます。「おめーのアプリねーから。Create a new appしろよ。」という感じで受け止めたのでCreate a new appしてみます。
アプリケーション名を適当につけて、リージョンをUnited Statesにする。
1 |
Name is already taken |
あら怒られた。アプリケーション名ってHeroku全体でユニークじゃないきゃいかんの?
適当にheroku-app1234って感じに変更して次へ進めます。
この手順まででgitリポジトリとアプリケーションのURLが付与されたみたい。
1 2 3 4 5 6 7 |
App URL: http://heroku-app1234.herokuapp.com/ Git URL: git@heroku.com:heroku-app1234.git Use the following code to set up your app for local development: git clone git@heroku.com:heroku-app1234.git -o heroku |
ローカルで開発するときはここからgit cloneしろよ!って書いてあるんだけどやってみたら失敗した。
1 2 3 4 5 6 7 |
$ git clone git@heroku.com:heroku-app1234.git -o heroku Cloning into 'heroku-app1234'... Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. |
Permission denied (publickey). ということはSSH鍵あたりのエラーだね。
Getting Startedから解決方法を探してみる。どうやらHeroku Toolbelt っていうどうやらコマンドラインツールが必要で、コマンド経由でherokuの認証を済ませなければいかんらしい。
下記から.pkgをダウンロード出来るのですが、ぼくはhomebrewを使っているのでコマンドでインスコしました。この辺はお好きに。
https://toolbelt.heroku.com/
homebrewでインストールする場合
1 |
$ brew install heroku-toolbelt |
インストールが完了したら、コマンドでheroku loginします。
1 2 3 4 5 6 7 |
$ heroku login Enter your Heroku credentials. Email: a.harada@example.com Password (typing will be hidden): Found existing public key: /Users/haradaatsushi/.ssh/id_rsa.pub Uploading SSH public key /Users/haradaatsushi/.ssh/id_rsa.pub... done Authentication successful. |
お、勝手に.ssh配下のid_rsa.pubが転送されたみたい。らくちんだなー。
これでgit clone出来るはずなのでもう一回やってみる。今度はうまく行きました!
1 |
$ git clone git@heroku.com:heroku-app1234.git |
ではgitリポジトリに変更を加えてみます。まずはプロジェクトルートにindex.htmlを作ってみる。
1 2 3 |
$ cd heroku-app1234 $ vim index.html hello heroku! |
また怒られた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ git add -A $ git commit -m "init" $ git push origin master Initializing repository, done. Counting objects: 3, done. Writing objects: 100% (3/3), 227 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) ! Push rejected, no Cedar-supported app detected To git@heroku.com:heroku-app1234.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'git@heroku.com:heroku-app1234.git' |
ググってみたところindex.phpがないとダメらしい。エラーメッセージ読んでもどこにもそんなことは書いてないぞ!HerokuってRubyのイメージあったけどPHPがデフォなの?
index.phpを追加して再びpush。今度はうまくいった。
1 2 |
$ vim index.php $lt;?php echo phpinfo(); ?> |
1 2 3 |
$ git add -A $ git commit -m "modify" $ git push origin master |
割り当てられたURLから確認してみる。PHP5.3がデフォで動いてた。
http://heroku-app1234.herokuapp.com/index.php
ふむー。
触りの部分の何となく理解出来たっぽい。次はRailsアプリをデプロイしてみますね!

原田 敦

最新記事 by 原田 敦 (全て見る)
- Rails Engineでブログ機能追加するgemを作る - 2015年3月15日
- WEBエンジニア一人だけでサービスを作りきる方法-夫婦のための自動ごはん予定お知らせサービス「GoHaaan」制作でやったこと - 2015年3月7日
- CentOS6でMariaDBのDynamic Columnsを試してみた - 2015年2月28日