skip to Main Content

I have this error when i try to make php artisan migrate


   IlluminateDatabaseQueryException 

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

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

      +34 vendor frames 
  35  artisan:37
      IlluminateFoundationConsoleKernel::handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))

I have already create my database on phpmyadmin. here is the configuration of my .env file

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=lsapp
DB_USERNAME=root
DB_PASSWORD=

and here the coonfiguration of mysql in my config/database.php

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'lsapp'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ]

help me solve that problem

5

Answers


  1. You may check if pdo_mysql extension is activated in php.ini file.

    Login or Signup to reply.
  2. In your php.ini configuration file uncomment the extension, remove ; :

    extension=php_pdo_mysql.dll
    

    If you’re on Linux make it:

    extension=pdo_mysql.so
    

    Then restart the server.

    If this isn’t working for you, you may need to install pdo_mysql extension into your php library.

    Login or Signup to reply.
  3. It may be that you are using two or more versions of php. So you better do:

    sudo apt install php-mysql

    This way you can be sure pdo_mysql extension is installed on each version.

    After this just restart apache2: sudo systemctl restart apache2.

    Login or Signup to reply.
  4. I had the same issue with this setup: Laravel, composer, nginx, mariadb, and php8 on Rocky Linux 8. When running php artisan migrate, I got the error that mysql could not find the driver. I installed php-mysql and then everything worked.

    sudo dnf install php-mysql -y
    

    or

    sudo yum install php-mysql y
    

    then

    sudo systemctl restart php-fpm
    

    Good luck and hope this helps.

    Failing
    enter image description here

    Working
    enter image description here

    Login or Signup to reply.
  5. I was able to solve it by executing the following command:

    sudo apt-get install -y php7.4-mysql
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search