AWSへのデプロイ(後編)

昨日の続きです。

 

手順5:Git, Docker, Docker-composeのインストール

ここからはpdfdではなくqiitaの手順が中心になります。

qiitaに記載のコマンドをコピペして実行で手順OK(少なくともエラーは出ていない。)

 

ちょいちょいy/n聞かれますが、全部yesでOK

 

手順をやって、さあログイン!としたら、

f:id:lawrence-twin:20200210211045p:plain


404エラー。。。なぜ、、、どうして、、、 

と考えましたが、nginx/default/sitesの設定変更していなかっただけでした。

 

■nginx/sites/default.conf

12     server_name localhost;

13     root /var/www/BlogProject01/public; //BlogProject01を追加

14     index index.php index.html index.htm;

 

 

その後docke-compose restart を実行後リスタートすると、以下のエラーが発生

■エラー

 

file_put_contents(/var/www/BlogSystem01/storage/framework/views/d597f254252265724ba218bb5d597230ea89af34.php): failed to open stream: Permission denied

 

どうやらまた書き込み権限らしい。laravelプロジェクトに移動して以下のコマンドも実行

■コマンド

cd storage

chmod 777 framework/

chmod 777 framework/views/

 

今度は以下のエラーが発生

SQLSTATE[HY000] [2002] Connection refused (SQL: select count(*) as aggregate from `posts`)

 

DB関連のエラーのため、マイグレーション不足が原因 

しかし、php artisan migrateを実行しても 「php command not found」が発生。

 

インストールが不足しているので、phpをインストール

■コマンド

apt install php

 

今度こそ、と思ったが以下のエラーが発生。 

■エラー内容

root@ip-10-0-0-200:/home/ubuntu/BlogSystem01# php artisan migrate 

   Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = default and table_name = migrations and table_type = 'BASE TABLE')

  1   PDOException::("could not find driver")

 /home/ubuntu/BlogSystem01/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=default", "default", "", )

 /home/ubuntu/BlogSystem01/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  Please use the argument -v to see more details.

root@ip-10-0-0-200:/home/ubuntu/BlogSystem01#

 

どうやらドライバーがないらしい。php-mysqlをいかんコマンドでインストール

■コマンド 

apt install php-mysql

 

これでphp artisan migrateが通るようになったが、今度は以下のエラーが発生

 

■エラー 

lluminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = default and table_name = migrations and table_type = 'BASE TABLE')

  Exception trace:

   1   PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")     /home/ubuntu/BlogSystem01/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=default", "default", "", )

 /home/ubuntu/BlogSystem01/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

 

認証方式が対応していないとのこと。

mysql 8.0の認証方式 

https://qiita.com/ucan-lab/items/3ae911b7e13287a5b917

 

1月に同じ問題に直面してたな。。。ちゃんと記事描こう。

mysqlのパスワード認証方法を変更し、再実行したらまたエラー内容が変わった。

 

 SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = default and table_name = migrations and table_type = 'BASE TABLE')

 

dockerを使ったlaravelでの「Connection refused」エラー

https://qiita.com/isaatsu0131/items/50f8dca389b60a1fd5b5

 

なんかデフォルトユーザだとうまくいく気がしなくなってきたので、以下の手順をもとにユーザを作成

 

MySQL入門】ユーザー作成の方法を解説!8.0からの変更点も紹介

https://www.sejuku.net/blog/82303

 

 

ユーザ変更、.envのを修正後にphp artisan migrateを実行すると、、、いけた。おそらくdefaultユーザの設定が良くなかったのだろう。

 

ひとまずこれで以下の通りデプロイ完了!初めてということもありここまで6時間くらいかかりましたが何とか終了。。。

 

ポートフォリオサイト

http://18.178.77.192/

f:id:lawrence-twin:20200210213159j:plain

 

ただ、ログインなどでまたエラーが起きているので再度調査が必要。https化や機能追加など課題もまだまだあります。