Help us understand the problem. What is going on with this article?

そろそろaws初めてみよか#2~CodeStarによるコード修正からDeployまで~

はじめに

そろそろaws初めてみよか~まずは触ってみた~で紹介したようにawsの海をもがいている訳ですが(笑)

CodeStarの環境が整ったので試しにコードを編集しCommitしてDeployまで流れるか確認
その後、DBのmigrateをしてみようと思います。
結果からお伝えすると、
- コードCommitからDeployまではOK
- DBのmigrateはNG
でした。

コード編集からDeployまで

Cloud9(IDE)を利用してコードを修正、それをGit CommitしてDeployまでの流れを確認しました。

CodeStarからプロジェクトを選択し、Cloud9を起動します。
暫くするとGitからPullしてきますので確認します。

今回は簡単にWelcomePageのタイトルを修正します。
修正と言っても「!!」を後ろにつけただけという(笑)

01.png

AWSのGitにCommitします。

ec2-user:~/environment $ cd php-laravel/
ec2-user:~/environment/php-laravel (master) $ git add .
ec2-user:~/environment/php-laravel (master) $ git commit -m 'change Title'
[master 42bc467] change Title
 Committer: EC2 Default User <ec2-user@ip-172-31-20-112.us-east-2.compute.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+), 1 deletion(-)
ec2-user:~/environment/php-laravel (master) $ git push origin master
Counting objects: 5, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 435 bytes | 435.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0)
To https://git-codecommit.us-east-2.amazonaws.com/v1/repos/php-laravel
   a0c0157..42bc467  master -> master
ec2-user:~/environment/php-laravel (master) $ 

すると勝手にDeployまで走っている様子がパイプラインの画面から確認できます。

02.png

実際のアプリケーションを確認するにはCodeStarダッシュボードの「アプリケーションのエンドポイント」をクリック

03.png

見辛いですが、タイトルが変わってます(笑)

04.png

こんな感じで開発していくのは分かるのですが…
本番環境とローカル環境のずれを前回確認しているのでどうやって実際に使っていくのかは
まだイメージできていません(^^;

DBとの接続

環境の確認

CodeStarによりプロジェクトを作成すると実行するインスタンスとCloud9(IDE)用のインスタンスが生成されます。
興味があるのは実行するインスタンス側なのでEC2ダッシュボード画面からインスタンス「php-laravel-WebApp」の「パブリック DNS (IPv4)」にTeraTermで接続します。
※ちなみに前回の記事ではプロジェクト名を「laravel」としてましたが、何度か削除に失敗して「php-laravel」としています。
 関連するリソースが綺麗に消えてくれなくて困っています(笑)


       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/
[ec2-user@ip-172-31-29-127 ~]$ cd /var/www/phplaravel/
[ec2-user@ip-172-31-29-127 phplaravel]$ ls
app        composer.json  database     package.json  resources   storage
artisan    composer.lock  gulpfile.js  phpunit.xml   routes      tests
bootstrap  config         index.php    public        server.php  vendor
[ec2-user@ip-172-31-29-127 phplaravel]$ php artisan migrate


  [Illuminate\Database\QueryException]
  could not find driver (SQL: select * from information_schema.tables where t
  able_schema = homestead and table_name = migrations)



  [PDOException]
  could not find driver

えっと...could not find driverって


       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/
[ec2-user@ip-172-31-29-127 ~]$ cd /var/www/phplaravel/
[ec2-user@ip-172-31-29-127 phplaravel]$ ls -alF
total 220
drwxr-xr-x 12 ec2-user ec2-user   4096 Feb  9 00:01 ./
drwxr-xr-x  8 root     root       4096 Feb  8 19:11 ../
drwxr-xr-x  6 ec2-user ec2-user   4096 Feb  9 00:01 app/
-rw-r--r--  1 ec2-user ec2-user   1646 Feb  9 00:01 artisan
drwxr-xr-x  3 ec2-user ec2-user   4096 Feb  9 00:01 bootstrap/
-rw-r--r--  1 ec2-user ec2-user   1283 Feb  9 00:01 composer.json
-rw-r--r--  1 ec2-user ec2-user 130327 Feb  9 00:00 composer.lock
drwxr-xr-x  2 ec2-user ec2-user   4096 Feb  9 00:01 config/
drwxr-xr-x  5 ec2-user ec2-user   4096 Feb  9 00:01 database/
-rw-r--r--  1 ec2-user ec2-user    543 Feb  9 00:01 .env
-rw-r--r--  1 ec2-user ec2-user    543 Feb  9 00:00 .env.example
-rw-r--r--  1 ec2-user ec2-user     61 Feb  9 00:01 .gitattributes
-rw-r--r--  1 ec2-user ec2-user     80 Feb  9 00:01 .gitignore
-rw-r--r--  1 ec2-user ec2-user    558 Feb  9 00:01 gulpfile.js
-rw-r--r--  1 ec2-user ec2-user   1776 Feb  9 00:01 index.php
-rw-r--r--  1 ec2-user ec2-user    390 Feb  9 00:00 package.json
-rw-r--r--  1 ec2-user ec2-user    930 Feb  9 00:01 phpunit.xml
drwxr-xr-x  5 ec2-user ec2-user   4096 Feb  9 00:01 public/
drwxr-xr-x  5 ec2-user ec2-user   4096 Feb  9 00:01 resources/
drwxr-xr-x  2 ec2-user ec2-user   4096 Feb  9 00:01 routes/
-rw-r--r--  1 ec2-user ec2-user    563 Feb  9 00:01 server.php
drwxrwxr-x  5 ec2-user apache     4096 Feb  9 00:01 storage/
drwxr-xr-x  2 ec2-user ec2-user   4096 Feb  9 00:01 tests/
drwxr-xr-x 32 ec2-user ec2-user   4096 Feb  9 00:01 vendor/
[ec2-user@ip-172-31-29-127 phplaravel]$ more .env
APP_ENV=local
APP_KEY=base64:CHANGEMECHANGEMECHANGEMECHANGEMECHANGEMECHA=
APP_DEBUG=false
APP_LOG_LEVEL=error
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
[ec2-user@ip-172-31-29-127 phplaravel]$

「.env」を覗くとローカルホストの「mysql」って書いてあります(汗
でもmysql入ってないし…


       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/
[ec2-user@ip-172-31-29-127 ~]$ rpm -qa | grep mysql
[ec2-user@ip-172-31-29-127 ~]$ 

そんな訳で追加インストール

無いのならインストールするしかないのでまずはPDOのmysqlをインストールしました。
$ sudo yum install -y php73-mysqlnd

するとPDOの例外が変わりましたね。
[PDOException]
SQLSTATE[HY000] [2002] Connection refused

DB_DATABASE、DB_USERNAME、DB_PASSWORDが違うので、これで正解です(笑)

[ec2-user@ip-172-31-29-127 phplaravel]$ sudo yum list *mysql*
Loaded plugins: priorities, update-motd, upgrade-helper
Available Packages
MySQL-python26.x86_64                          1.2.3-11.14.amzn1    amzn-main
MySQL-python27.x86_64                          1.2.3-11.14.amzn1    amzn-main
apr-util-mysql.x86_64                          1.5.4-6.18.amzn1     amzn-main
collectd-mysql.x86_64                          5.8.0-2.19.amzn1     amzn-main
dovecot-mysql.x86_64                           1:2.2.10-5.17.amzn1  amzn-main
exim-mysql.x86_64                              4.92-1.25.amzn1      amzn-updates
freeradius-mysql.x86_64                        2.2.6-7.16.amzn1     amzn-main
libdbi-dbd-mysql.x86_64                        0.8.3-5.1.5.amzn1    amzn-main
lighttpd-mod_authn_mysql.x86_64                1.4.53-1.36.amzn1    amzn-updates
lighttpd-mod_mysql_vhost.x86_64                1.4.53-1.36.amzn1    amzn-updates
mod_auth_mysql.x86_64                          1:3.0.0-18.10.amzn1  amzn-main
mysql.noarch                                   5.5-1.6.amzn1        amzn-main
mysql-bench.noarch                             5.5-1.6.amzn1        amzn-main
mysql-common.noarch                            5.5-1.6.amzn1        amzn-main
mysql-config.x86_64                            5.5.62-1.23.amzn1    amzn-updates
mysql-connector-java.noarch                    1:5.1.12-2.10.amzn1  amzn-main
mysql-connector-odbc.x86_64                    5.1.11-1.12.amzn1    amzn-main
mysql-devel.noarch                             5.5-1.6.amzn1        amzn-main
mysql-embedded.noarch                          5.5-1.6.amzn1        amzn-main
mysql-embedded-devel.noarch                    5.5-1.6.amzn1        amzn-main
mysql-libs.noarch                              5.5-1.6.amzn1        amzn-main
mysql-server.noarch                            5.5-1.6.amzn1        amzn-main
mysql-test.noarch                              5.5-1.6.amzn1        amzn-main
mysql51.x86_64                                 5.1.73-8.72.amzn1    amzn-main
mysql51-bench.x86_64                           5.1.73-8.72.amzn1    amzn-main
mysql51-common.x86_64                          5.1.73-8.72.amzn1    amzn-main
mysql51-devel.x86_64                           5.1.73-8.72.amzn1    amzn-main
mysql51-embedded.x86_64                        5.1.73-8.72.amzn1    amzn-main
mysql51-embedded-devel.x86_64                  5.1.73-8.72.amzn1    amzn-main
mysql51-libs.i686                              5.1.73-8.72.amzn1    amzn-main
mysql51-libs.x86_64                            5.1.73-8.72.amzn1    amzn-main
mysql51-server.x86_64                          5.1.73-8.72.amzn1    amzn-main
mysql51-test.x86_64                            5.1.73-8.72.amzn1    amzn-main
mysql55.x86_64                                 5.5.62-1.23.amzn1    amzn-updates
mysql55-bench.x86_64                           5.5.62-1.23.amzn1    amzn-updates
mysql55-devel.x86_64                           5.5.62-1.23.amzn1    amzn-updates
mysql55-embedded.x86_64                        5.5.62-1.23.amzn1    amzn-updates
mysql55-embedded-devel.x86_64                  5.5.62-1.23.amzn1    amzn-updates
mysql55-libs.i686                              5.5.62-1.23.amzn1    amzn-updates
mysql55-libs.x86_64                            5.5.62-1.23.amzn1    amzn-updates
mysql55-server.x86_64                          5.5.62-1.23.amzn1    amzn-updates
mysql55-test.x86_64                            5.5.62-1.23.amzn1    amzn-updates
mysql56.x86_64                                 5.6.46-1.35.amzn1    amzn-updates
mysql56-bench.x86_64                           5.6.46-1.35.amzn1    amzn-updates
mysql56-common.i686                            5.6.46-1.35.amzn1    amzn-updates
mysql56-common.x86_64                          5.6.46-1.35.amzn1    amzn-updates
mysql56-devel.x86_64                           5.6.46-1.35.amzn1    amzn-updates
mysql56-embedded.x86_64                        5.6.46-1.35.amzn1    amzn-updates
mysql56-embedded-devel.x86_64                  5.6.46-1.35.amzn1    amzn-updates
mysql56-errmsg.x86_64                          5.6.46-1.35.amzn1    amzn-updates
mysql56-libs.i686                              5.6.46-1.35.amzn1    amzn-updates
mysql56-libs.x86_64                            5.6.46-1.35.amzn1    amzn-updates
mysql56-server.x86_64                          5.6.46-1.35.amzn1    amzn-updates
mysql56-test.x86_64                            5.6.46-1.35.amzn1    amzn-updates
mysql57.x86_64                                 5.7.28-1.14.amzn1    amzn-updates
mysql57-common.i686                            5.7.28-1.14.amzn1    amzn-updates
mysql57-common.x86_64                          5.7.28-1.14.amzn1    amzn-updates
mysql57-devel.x86_64                           5.7.28-1.14.amzn1    amzn-updates
mysql57-embedded.x86_64                        5.7.28-1.14.amzn1    amzn-updates
mysql57-embedded-devel.x86_64                  5.7.28-1.14.amzn1    amzn-updates
mysql57-errmsg.x86_64                          5.7.28-1.14.amzn1    amzn-updates
mysql57-libs.i686                              5.7.28-1.14.amzn1    amzn-updates
mysql57-libs.x86_64                            5.7.28-1.14.amzn1    amzn-updates
mysql57-server.x86_64                          5.7.28-1.14.amzn1    amzn-updates
mysql57-test.x86_64                            5.7.28-1.14.amzn1    amzn-updates
nagios-plugins-mysql.x86_64                    1.4.16-5.8.amzn1     amzn-main
perl-DBD-MySQL.x86_64                          4.023-5.17.amzn1     amzn-main
perl-DBD-MySQL55.x86_64                        4.023-5.23.amzn1     amzn-main
perl-DBD-MySQL56.x86_64                        4.023-5.21.amzn1     amzn-main
perl-DateTime-Format-MySQL.noarch              0.04-18.2.amzn1      amzn-main
perl-Time-Piece-MySQL.noarch                   0.05-20.2.amzn1      amzn-main
php-ZendFramework-Db-Adapter-Mysqli.noarch     1.12.20-1.12.amzn1   amzn-main
php-ZendFramework-Db-Adapter-Pdo-Mysql.noarch  1.12.20-1.12.amzn1   amzn-main
php-mysql.x86_64                               5.3.29-1.8.amzn1     amzn-main
php-mysqlnd.x86_64                             5.3.29-1.8.amzn1     amzn-main
php54-mysql.x86_64                             5.4.45-1.75.amzn1    amzn-main
php54-mysqlnd.x86_64                           5.4.45-1.75.amzn1    amzn-main
php55-mysqlnd.x86_64                           5.5.38-2.119.amzn1   amzn-main
php56-mysqlnd.x86_64                           5.6.40-1.143.amzn1   amzn-updates
php70-mysqlnd.x86_64                           7.0.33-1.32.amzn1    amzn-updates
php71-mysqlnd.x86_64                           7.1.33-1.43.amzn1    amzn-updates
php72-mysqlnd.x86_64                           7.2.26-1.19.amzn1    amzn-updates
php73-mysqlnd.x86_64                           7.3.13-1.22.amzn1    amzn-updates
rsyslog-mysql.x86_64                           5.8.10-9.26.amzn1    amzn-main
ruby-mysql.x86_64                              2.8.2-1.11.amzn1     amzn-main

[ec2-user@ip-172-31-29-127 phplaravel]$ sudo yum install -y php73-mysqlnd
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> Package php73-mysqlnd.x86_64 0:7.3.13-1.22.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch        Version                 Repository         Size
================================================================================
Installing:
 php73-mysqlnd      x86_64      7.3.13-1.22.amzn1       amzn-updates      336 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 336 k
Installed size: 812 k
Downloading packages:
php73-mysqlnd-7.3.13-1.22.amzn1.x86_64.rpm                 | 336 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php73-mysqlnd-7.3.13-1.22.amzn1.x86_64                       1/1
  Verifying  : php73-mysqlnd-7.3.13-1.22.amzn1.x86_64                       1/1

Installed:
  php73-mysqlnd.x86_64 0:7.3.13-1.22.amzn1

Complete!

[ec2-user@ip-172-31-29-127 phplaravel]$ php artisan migrate


  [Illuminate\Database\QueryException]
  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s
  chema.tables where table_schema = homestead and table_name = migrations)



  [PDOException]
  SQLSTATE[HY000] [2002] Connection refused


[ec2-user@ip-172-31-29-127 phplaravel]$

RDS(DBサーバ)と接続する準備は整ったのでまたキャプチャー取り始めます(笑)

imp555sti
SEで小規模Web開発を行っていましたが激務が災いして病休。その後復職しましたが今は開発SEから運用に配置換えして基本的には平和な日々(のはず…)を送っています(笑) と思っていたら開発にお呼びがかかり…開発に戻されましたとさ…どうなることやら(苦笑)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした