I have a Laravel 5.4 project on my Ubuntu 14.04 (VPS with Plesk 12.5.30). After creating the database and setted up the .env file with required information I ran php artisan migrate
and exceptions were thrown:
[IlluminateDatabaseQueryException]
could not find driver (SQL: select * from information_schema.tables where table_schema = pmaramaldb and table_name = migrations)[PDOException]
could not find driver
My .env file has:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pmaramaldb
DB_USERNAME=user
DB_PASSWORD=password
I’ve followed most of the guides to solve this error and there wasn’t any positive results:
Enabling Extension Solution:
The php.ini file is being generated automatically, I guess this is made by Plesk. At the start of the file it says:
; ATTENTION!
;
; DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
; SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.
So I’ve tried it anyway. After that I’ve restarted Apache and then tried again… Didn’t work.
Installing php7.0-mysql Solution:
I’ve also tried to install MySQL in case is not:
user@server:/var/www/vhosts$ sudo apt-get install php7.0-mysql
Leyendo lista de paquetes… Hecho
Creando árbol de dependencias
Leyendo la información de estado… Hecho
php7.0-mysql is already the newest version.
0 actualizados, 0 se instalarán, 0 para eliminar y 67 no actualizados.
** SQL Lite Install Solution:**
I’ve also tried as question link says: sudo apt-get install php5-sqlite
and the result was:
user@server:/var/www/vhosts/system/maramal.io/etc$ sudo apt-get install php5-sqlite
Leyendo lista de paquetes… Hecho
Creando árbol de dependencias
Leyendo la información de estado… Hecho
php5-sqlite is already the newest version.
0 actualizados, 0 se instalarán, 0 para eliminar y 67 no actualizados.
Composer Dump-autoload Solution:
It didn’t work either. I’ve tried composer dump-autoload
and it didn’t work.
After ran the command php -i
:
PDO
PDO support => enabled
PDO drivers =>
…
PHP Version => 5.6.30-1+deb.sury.org~trusty+1
Well, I am not sure if this has anything to do with the error, but the version shown by running php -v
is:
user@server: ~/path$ php -v
PHP 5.6.30-1+deb.sury.org~trusty+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
12
Answers
You can try these following command
Then restart your apache server. After then
reconfigure your
.env
fileActually, I’m pretty sure that you are not aware of your PHP – versions and used the wrong paths:
For your vendor PHP version ( 5.6 by sury.org ), you would use PHP – commands as “/usr/bin/php”, but when you use different PHP – versions, as for example the ones from Plesk, then you have different paths:
Your PHP – commands for possible additional PHP versions ( 7.0 and 7.1 if you installed the sury.org MAIN ppa PHP versions from https://launchpad.net/~ondrej/+archive/ubuntu/php ) would be:
Show the installed modules for each PHP version with the “-m” option string and use the “-i” option string for informations ( example ):
To use the “composer”, you would certainly as well use the FULL path of your PHP executable ( example ):
Additional “composer” – commands are then:
There’s a conflict between the PHP that is used by Apache and the PHP that is linked to the command line. (It happens more often that it should to be honest).
What is typically done is:
This tells you which php will be expecuted when running in the command line. e.g.
/usr/bin/php
Then link or copy the correct PHP version to an executable path:
or the following should also work.
Also suggested if you want to be able to manually install mods:
This way your CLI will match your webserver.
Update:
If as noted in this answer if you are using Ubuntu with multiple alternative installations of PHP you can do:
As an alternative solution be sure you have installed php7-mysql
try to run command below
or, if you want to automatically install the current version
I had the same scenario you have. I did resolve mine the following:
1) on your terminal, type
this will output your current php.ini configuration file path.
2) edit php.ini using vim or your preferred editor.
note that /etc/php.ini is your path file for your php.ini. it may be different on your machine.
3) find ;extension=php_pdo_mysql.dll and uncomment it by removing semicolon (;)
4) save your php.ini change/s
**5) restart the web server to apply the changes
**6) Now run your command.
hope this helps for you.
clear artisan cache
and
that’s it
Your database driver is missing. To solve the probelem
First install the driver
For ubuntu: For mysql database.
You also can search for other database systems.
You also can search for the driver:
Same problem, ubuntu 17.10, Laravel 5.5.
$
sudo apt install php7.1-pdo php7.1-mysql
A nice quick fix, hope this helps
Ok I once experienced this error… I don’t know why but it looks like in php 7.3 there is problem in relation to drivers or something there what I did was switch back to php 7.2 and everything worked fine…
in linux do like that
first check your php version like this :
after you get version number for example i get 7.1 then install like that
and need to restart apache2
If you are using WSL2, with docker, and recently had an incident with switching db drivers, you could try: