(2022/07/18現在)【Heroku】新規登録、CLIインストール、CLIログイン、新規プロジェクト作成、ブラウザ確認、までの手順を確認しました

Heroku環境構築の備忘録です。
ググれば情報はたくさん出てきますが、自分がこの手の記事を探す際、新しい記事ほどありがたいので残すことにしました。

Herokuの新規登録

Herokuの日本語サイト(https://jp.heroku.com/)の新規登録ボタンから進めば特に問題なく完了できました。

登録したメールアドレスに仮登録メールが届いているので、メール本文の登録URLをクリックすると以下の画面がブラウザで開きます。

利用規約の確認と同意。

以上で新規登録完了です!

Heroku CLIのセットアップ

Herokuの操作はCUIで行うため、Heroku CLIをセットアップする必要があります。
また、デプロイのためにgitを使うとのことなのであらかじめgitをインストールしておく必要があります。

gitのインストール

私はgithubを使って開発していたので、すでにgitコマンドが入っていました。入っていない場合は以下を参考にインストールしてください。

Git - Installing Git
Git - First-Time Git Setup

Homebrewのインストール

Heroku CLIをインストールするには、brewコマンドが必要となります。私のmac mini(Monterey)には 入っていなかったのでHomebrewをインストールしました。

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

インストール成功。
/opt/homebrew/binにPATHが通ってないので「Next steps」を見ると、2つのコマンドを実行する必要があるとのこと。

HEAD is now at 55598bacae7 vite: update 3.0.1 bottle.
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

〜

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

言われるがままにコマンド打って無事にPATHが通りました。

% echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
% eval "$(/opt/homebrew/bin/brew shellenv)"
% bre
break  brew # PATHが通ったので補完が効く

インストール状態も良好。

% brew doctor
Your system is ready to brew.
% brew update
Already up-to-date.

Homebrew公式サイトです。

Homebrew
The Missing Package Manager for macOS (or Linux).

Heroku CLIのインストール

Homebrewが入ったので、本命のHeroku CLIをインストールしていきます。
Heroku CLIの公式ページからコピーした以下のmacOS用コマンドを実行します。

% brew tap heroku/brew && brew install heroku
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
Running `brew update --auto-update`...

==> Tapping heroku/brew
Cloning into '/opt/homebrew/Library/Taps/heroku/homebrew-brew'...
remote: Enumerating objects: 1798, done.
remote: Counting objects: 100% (183/183), done.
remote: Compressing objects: 100% (137/137), done.
remote: Total 1798 (delta 46), reused 183 (delta 46), pack-reused 1615
Receiving objects: 100% (1798/1798), 236.11 KiB | 4.45 MiB/s, done.
Resolving deltas: 100% (442/442), done.
Tapped 2 formulae (16 files, 293.3KB).
==> Downloading https://nodejs.org/download/release/v14.19.0/node-v14.19.0-darwin-x64.tar.xz
######################################################################## 100.0%
==> Downloading https://cli-assets.heroku.com/heroku-v7.60.2/heroku-v7.60.2.tar.xz
######################################################################## 100.0%
==> Installing heroku from heroku/brew
==> Installing dependencies for heroku/brew/heroku: heroku/brew/heroku-node
==> Installing heroku/brew/heroku dependency: heroku/brew/heroku-node
🍺  /opt/homebrew/Cellar/heroku-node/14.19.0: 6 files, 73.5MB, built in 4 seconds
==> Installing heroku/brew/heroku
==> Caveats
To use the Heroku CLI's autocomplete --
  Via homebrew's shell completion:
    1) Follow homebrew's install instructions https://docs.brew.sh/Shell-Completion
        NOTE: For zsh, as the instructions mention, be sure compinit is autoloaded
              and called, either explicitly or via a framework like oh-my-zsh.
    2) Then run
      $ heroku autocomplete --refresh-cache
  OR
  Use our standalone setup:
    1) Run and follow the install steps:
      $ heroku autocomplete

zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions
==> Summary
🍺  /opt/homebrew/Cellar/heroku/7.60.2: 29,032 files, 67.9MB, built in 16 seconds
==> Running `brew cleanup heroku`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> heroku
To use the Heroku CLI's autocomplete --
  Via homebrew's shell completion:
    1) Follow homebrew's install instructions https://docs.brew.sh/Shell-Completion
        NOTE: For zsh, as the instructions mention, be sure compinit is autoloaded
              and called, either explicitly or via a framework like oh-my-zsh.
    2) Then run
      $ heroku autocomplete --refresh-cache
  OR
  Use our standalone setup:
    1) Run and follow the install steps:
      $ heroku autocomplete

zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions

特にエラーもなくインストール完了しました。

Heroku CLIのバージョンは以下の通りです。

% heroku --version
 ›   Warning: Our terms of service have changed: https://dashboard.heroku.com/terms-of-service
heroku/7.60.2 darwin-x64 node-v14.19.0

Heroku CLIのインストールページは以下です。

Heroku CLI | Heroku Dev Center
Heroku CLI をダウンロード、インストール、および使用を開始する方法。Heroku Toolbelt の一部として使用される Heroku CLI。

Herokuにログイン

Heroku CLIのログインコマンドを実行。何かキーを押してブラウザでログインしてください、とのことなので何か適当なキーを押します。

% heroku login 
% heroku: Press any key to open up the browser to login or q to exit:

ブラウザが起動して、Heroku CLIのログイン画面がでます。Log Inボタンを押して、メールアドレス・パスワードを入力して、ログインが完了します。

ログインが成功しました。
メールアドレスと API トークンが ~/.netrc​ に保存されました。

% heroku login 
heroku: Press any key to open up the browser to login or q to exit: 
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/***
Logged in as ***@gmail.com
% ls -a ~ | grep .netrc
.netrc
Heroku CLI | Heroku Dev Center
Heroku CLI をダウンロード、インストール、および使用を開始する方法。Heroku Toolbelt の一部として使用される Heroku CLI。

Herokuに新規プロジェクトの作成

プロジェクトのディレクトリと適当なファイルを作成します。

% mkdir helloworld
% cd helloworld 
% touch index.php
% touch composer.json
% vi index.php 
% cat index.php 
<?php
echo "Hello World";

次にプロジェクトをgitに追加し、herokuにデプロイします。
この辺りの動きは今はよくわかっていないのであとで確認していきます。

% git init
% git add .
% git commit -a -m "first commit"

% heroku create take424helloworld
Creating ⬢ take424helloworld... done
https://take424helloworld.herokuapp.com/
| https://git.heroku.com/take424helloworld.git % git push heroku master remote: Verifying deploy... done. To https://git.heroku.com/take424helloworld.git * [new branch] master -> master

最後にHerokuにデプロイしたプロジェクトをブラウザで確認します。

% heroku open

無事ブラウザで表示されました!

Herokuの管理コンソールにもプロジェクトが追加されています。

新規プロジェクトの作成部分は以下の記事の通りに実施しました。
ありがとうございました。

Heroku アカウント登録してデプロイするまでの簡単な使い方
Herokuにデプロイするまで簡単な手順です。今回はphpをデプロイします。

最後に

Herokuへの新規登録、Heroku CLIのセットアップ、ログイン、新規プロジェクト作成からのブラウザ動作確認までざっと確認することができました。

次の課題として、node.jsやredisのインストール、テスト環境の構築、契約状況はどうなっているのか等々、気になることがまだまだあるので順番に見ていきたいと思います。

以上、参考になれば幸いです。

コメント

タイトルとURLをコピーしました