Herokuメモ(1) - phpのサンプルコードをデプロイ

#やりたいこと
サーバレスとかデプロイとかかじった知識しかないので、手を動かしてみる。
とりあえず
https://devcenter.heroku.com/articles/getting-started-with-php
をやってみる。

##動作環境
- Surface Go
- Windows 10 Home

##インストール
###Gitのインストール
- https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- アカウント作ったりいろいろは後述

###phpのインストール
- https://windows.php.net/download#php-7.4
- 下記を参考にした
 - https://weblabo.oscasierra.net/php-71-windows-install/
 - https://webkaru.net/php/windows-php-instal/

###composerのインストール
- https://getcomposer.org/doc/00-intro.md#using-the-installer

###herokuのインストール
- https://devcenter.heroku.com/articles/getting-started-with-php#set-up

##herokuログイン
- 基本的にPowerShellで作業
- PowerShellからVimが立ち上がらなくてイライラしたので設定 -> 後述

'''
PS C:\Users\XXXX> 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/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Logging in... done
Logged in as xxxx
PS C:\Users\XXXX>
```

- Press any key...のところでブラウザが起動する、CLI loginすると先に進む

##テンプレをclone

```
PS C:\Users\XXXX\work> git clone https://github.com/heroku/php-getting-started.git
Cloning into 'php-getting-started'...
remote: Enumerating objects: 189, done.
remote: Total 189 (delta 0), reused 0 (delta 0), pack-reused 189R
Receiving objects: 100% (189/189), 49.78 KiB | 1.38 MiB/s, done.
Resolving deltas: 100% (77/77), done.
```

- この時点のgitのconfigはこんな感じ

```
PS C:\Users\XXXX\work\php-getting-started> cat .\.git\config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/heroku/php-getting-started.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
```

##heroku create

```
PS C:\Users\XXXX\work\php-getting-started> heroku create
Creating app... done, ? floating-depths-27991
https://xxxxxxxx-xxxxxx-xxxxx.herokuapp.com/ | https://git.heroku.com/xxxxxxxx-xxxxxx-xxxxx.git
```

- git configがこう変わる

```
PS C:\Users\XXXX\work\php-getting-started> cat .\.git\config                                             [core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/heroku/php-getting-started.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "heroku"]
        url = https://git.heroku.com/xxxxxxxx-xxxxxx-xxxxx.git
        fetch = +refs/heads/*:refs/remotes/heroku/*
```

- remoteにherokuができる
 - このherokuにpushするとdeployされる仕組みらしい
- heroku createで、https://xxxxxxxx-xxxxxx-xxxxx.herokuapp.com/が作られる
 - この時点でこのURLをブラウザに入れると、Welcome to your new app!と表示される

##herokuにpush

```
PS C:\Users\XXXX\work\php-getting-started> git push heroku master
Enumerating objects: 178, done.
Counting objects: 100% (178/178), done.
Delta compression using up to 4 threads
Compressing objects: 100% (95/95), done.
Writing objects: 100% (178/178), 48.02 KiB | 3.00 MiB/s, done.
Total 178 (delta 69), reused 178 (delta 69), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        NOTICE: No runtime required in composer.json; requirements
remote:        from dependencies in composer.lock will be used for selection
remote:        - php (7.4.5)
remote:        - apache (2.4.43)
remote:        - nginx (1.18.0)
remote: -----> Installing dependencies...
remote:        Composer version 1.10.5 2020-04-10 11:44:22
remote:        Loading composer repositories with package information
remote:        Installing dependencies from lock file
remote:        Package operations: 12 installs, 0 updates, 0 removals
remote:          - Installing psr/log (1.0.2): Downloading (100%)
remote:          - Installing monolog/monolog (1.22.1): Downloading (100%)
remote:          - Installing symfony/routing (v3.2.7): Downloading (100%)
remote:          - Installing symfony/polyfill-mbstring (v1.3.0): Downloading (100%)
remote:          - Installing symfony/http-foundation (v3.2.7): Downloading (100%)
remote:          - Installing symfony/event-dispatcher (v3.2.7): > Downloading (100%)
remote:          - Installing symfony/debug (v3.2.7): Downloading (100%)
remote:          - Installing symfony/http-kernel (v3.2.7): Downloading (100%)
remote:          - Installing pimple/pimple (v3.0.2): Downloading (100%)
remote:          - Installing silex/silex (v2.0.4): Downloading (100%)
remote:          - Installing twig/twig (v2.3.0): Downloading (100%)
remote:          - Installing symfony/twig-bridge (v3.2.7): Downloading (100%)
remote:        Generating optimized autoload files
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 14.9M
remote: -----> Launching...
remote:        Released v3
remote:        https://xxxxxxxx-xxxxxx-xxxxx.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/xxxxxxxx-xxxxxx-xxxxx.git
 * [new branch]      master -> master
```

- cloneしたphp-getting-startedの中のphpが表示された

[その2](https://qiita.com/nabechiki/items/9422f087c51df08be608)へ続く。