AWSのCloud9でLaravelを使用

Laravelを学習中。

 

本に沿ってやっているんだけど、

以下のエラーが出て、エラー原因がわからない。

 

ec2-user:~/environment/cms $ php artisan migrate

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

at /home/ec2-user/environment/cms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|

Exception trace:

1 PDOException::("could not find driver")
/home/ec2-user/environment/cms/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

2 PDO::__construct("mysql:host=localhost;port=3306;dbname=c9", "root", "root", [])
/home/ec2-user/environment/cms/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

Please use the argument -v to see more details.
ec2-user:~/environment/cms $

 

 

MySql5.5じゃなくて5.7でないとダメだとかいう記述があったから、

5.7にしたけどそれでもうまくいかない。

 
php.iniの設定だとかいう記述もあったけど、
php - Artisan migrate could not find driver - Stack Overflow


結局、原因は以下が入っていなかったことっぽい。
どうやら本に記載されたサンプルコードでは、mysqlndがインストールできていなかったようだ。

  Installing : php72-pecl-mcrypt-1.0.1-3.5.amzn1.x86_64                                                                                                                                                                                         1/2 
  Installing : php72-mysqlnd-7.2.28-1.21.amzn1.x86_64                                                                                                                                                                                           2/2 

 

 

 こちらの方法で無事、実行できるようになった。
$php artisan migrateができない→ - Qiita

sudo yum -y install php72 php72-cli php72-common php72-devel php72-mysqlnd php72-pdo php72-xml php72-gd php72-intl php72-mbstring php72-mcrypt php72-opcache php72-pecl-apcu php72-pecl-imagick php72-peclmemcached php72-pecl-redis php72-pecl-xdebug

たぶん、このコマンドでOK。

$ sudo yum -y install php72-mysqlnd php72-mcrypt