phpbrew からインストールしたPHPでartisan migrae できない

  • このエントリーをはてなブックマークに追加
  • Pocket
  • LINEで送る

プロジェクトごとにPHPのバージョン管理をするため、先日、phpbrewを導入しました。

しばらくは問題なく使えていたのですが、Laravelの開発のためartisanコマンドを実行したときにエラーが。

$ php artisan migrate

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

  at /var/www/public/laravel_app/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")
      /var/www/public/laravel_app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=localhost;port=3306;dbname=laravel_app", "laravel_user", "laravel_passwd", [])
      /var/www/public/laravel_app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  Please use the argument -v to see more details.

PDOExeption::(“coult not find driver”) となってます。PDOドライバーがない??

phpのインストール状況を見てみました。

$ php -i | grep PDO
PDO
PDO support => enabled
PDO drivers =>

むむ…。確かに設定されていない…

defaultバリアントにもpdoは含まれているんですけどね…念のためインストールしなおし。

$ phpbrew install 7.4.21 +default +pdo +mysql
===> phpbrew will now build 7.4.21
===> Loading and resolving variants...
Checking distribution checksum...
Checksum matched: 36ec6102e757e2c2b7742057a700bbff77c76fa0ccbe9c860398c3d24e32822a
===> Distribution file was successfully extracted, skipping...

# 中略 #

* We found that you enabled 'mysql' variant, you might need to setup your
  'pdo_mysql.default_socket' or 'mysqli.default_socket' in your php.ini file.

* To configure your installed PHP further, you can edit the config file at
    /home/uchiida/.phpbrew/php/php-7.4.21/etc/php.ini

To use the newly built PHP, try the line(s) below:

    $ phpbrew use php-7.4.21

Or you can use switch command to switch your default php to php-7.4.21:

    $ phpbrew switch php-7.4.21

Enjoy!

バリアントをつけなおしてみても、状況は変わらず。うーんなんなのか…

メッセージをよく見てみると、「mysqlバリアントを有効にするには、php.iniでソケットをセットアップする必要があるかもよ」と書かれています。

改めてGithubのREADMEを見直してみたところ、phpbrew config でiniを修正することができると書いてあります。

https://github.com/phpbrew/phpbrew/blob/master/README.ja.md#extention-installer

記載の通りにコマンド入力したら、エディタが立ち上がったので、そのまま保存して終了しました。

これで直ったのかな~と思いつつ、PHPの情報を見てみると、、、

$ php -i | grep PDO
PDO
PDO support => enabled
PDO drivers => mysql
PDO Driver for MySQL => enabled

直ってました。artisan migrate コマンドも実行できました。

iniファイルの変更は、別途行わないといけないみたいですね…

以上です。あなたのお役に立てればうれしいです。

  • このエントリーをはてなブックマークに追加
  • Pocket
  • LINEで送る

SNSでもご購読できます。

コメントを残す

*