Laravel: PDOException: could not find driver

I am developing a website on a server I only have access to MySQL and FTP, so all commands I run are through the b374k php shell . I am experiencing a Laravel problem with SQL driver. I tried switching to file-hosted SQLite (in database/database.sqlite), but the thrown exception is the same as when using MySQL. The input & output of the console is as follows:

   php artisan migrate:refresh --seed
    [Illuminate\Database\QueryException]
could not find driver (SQL: select * from sqlite_master where type = 'table ' and name = migrations)
 [Doctrine\DBAL\Driver\PDOException]
could not find driver
 [PDOException]
could not find driver

The Apache extensions installed on the server are:

    /etc/php/5.6/apache2/conf.d/10-mysqlnd.ini, 
/etc/php/5.6/apache2/conf.d/10-opcache.ini,
 /etc/php/5.6/apache2/conf.d/10-pdo.ini,
 /etc/php/5.6/apache2/conf.d/15-xml.ini, 
/etc/php/5.6/apache2/conf.d/20-calendar.ini,
 /etc/php/5.6/apache2/conf.d/20-ctype.ini, 
/etc/php/5.6/apache2/conf.d/20-curl.ini,
 /etc/php/5.6/apache2/conf.d/20-dom.ini, 
/etc/php/5.6/apache2/conf.d/20-exif.ini, 
/etc/php/5.6/apache2/conf.d/20-fileinfo.ini, 
/etc/php/5.6/apache2/conf.d/20-ftp.ini, /etc/php/5.6/apache2/conf.d/20-gd.ini, 
/etc/php/5.6/apache2/conf.d/20-gettext.ini, 
/etc/php/5.6/apache2/conf.d/20-iconv.ini, 
/etc/php/5.6/apache2/conf.d/20-json.ini, 
/etc/php/5.6/apache2/conf.d/20-mbstring.ini, 
/etc/php/5.6/apache2/conf.d/20-mcrypt.ini, 
/etc/php/5.6/apache2/conf.d/20-mysql.ini, 
/etc/php/5.6/apache2/conf.d/20-mysqli.ini, 
/etc/php/5.6/apache2/conf.d/20-pdo_mysql.ini,
 /etc/php/5.6/apache2/conf.d/20-phar.ini, 
/etc/php/5.6/apache2/conf.d/20-posix.ini, 
/etc/php/5.6/apache2/conf.d/20-readline.ini, 
/etc/php/5.6/apache2/conf.d/20-shmop.ini, 
/etc/php/5.6/apache2/conf.d/20-simplexml.ini, 
/etc/php/5.6/apache2/conf.d/20-sockets.ini,
 /etc/php/5.6/apache2/conf.d/20-sysvmsg.ini,
 /etc/php/5.6/apache2/conf.d/20-sysvsem.ini,
 /etc/php/5.6/apache2/conf.d/20-sysvshm.ini,
 /etc/php/5.6/apache2/conf.d/20-tokenizer.ini, 
/etc/php/5.6/apache2/conf.d/20-wddx.ini,
 /etc/php/5.6/apache2/conf.d/20-xmlreader.ini, 
/etc/php/5.6/apache2/conf.d/20-xmlwriter.ini, 
/etc/php/5.6/apache2/conf.d/20-xsl.ini, 
/etc/php/5.6/apache2/conf.d/20-zip.ini

What can be the problem and how can I fix it? (I don't have access to root bash)


Solution 1:

If you can, run :

composer update

composer require doctrine/dbal

It looks like you have a missing dependency

Edit:

You might need to comment out the following in your php.ini file.

;extension=pdo_mysql.so

Taken from this post: Laravel 5 PDOException Could Not Find Driver . I think I had to do something exactly like this when setting up laravel on digital ocean.

Solution 2:

Your database driver is missing. To solve the probelm

First install the driver

For ubuntu: For mysql database.

sudo apt-get install php5.6-mysql/php7.2-mysql

You also can search for other database systems.

You also can search for the driver:

sudo apt-cache search drivername

Then Run the cmd php artisan migrate

Solution 3:

I got the same error when running my test suite. It was working before but it stopped working after I upgraded php. So I did

sudo apt-get install php-sqlite3

and it worked.

Solution 4:

Even simpler in Ubuntu (18.04)

apt install php-mysql

Done. No need to edit any .ini files.

Happy coding!