I have a bad experience while installing laravel. However, I was able to do so and move to the next level. I used generators and created my migrations. But when I type the last command
安装laravel时,我有一次很糟糕的经历。然而,我能够这样做,并进入下一个阶段。我使用生成器生成迁移。但是当我输入最后一个命令时
php artisan migrate
It's throwing a PDOException - could not find driver.
它抛出一个PDOException——找不到驱动程序。
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
That's my configuration in config/database.php.
这是我在config/database.php中的配置。
I tried searching on * and laravel forums and people suggest that it's PDO problem and not artisan's or php's - I followed those suggestions like adding
我尝试在*和laravel论坛上搜索,人们认为这是PDO问题,而不是artisan或php——我遵循了这些建议,比如添加
extension=pgsql.so
extension=pdo_pgsql.so
in php.ini
在php . ini中
No positive result. It always says [PDOException]could not find driver.
没有积极的结果。它总是说[PDOException]找不到司机。
Can someone please help resolving this.
谁能帮忙解决这个问题吗?
Environment that I am using: Mac, laravel 4, MAMP PRO with php 5.4.4
我正在使用的环境:Mac、laravel 4、MAMP PRO和php 5.4.4
20 个解决方案
#1
32
You can use
您可以使用
sudo apt-get install php7-mysql
or
或
sudo apt-get install php5-mysql
or
或
sudo apt-get install php-mysql
This worked for me.
这为我工作。
#2
18
This worked for me:
这工作对我来说:
sudo apt-get install php5-sqlite
This installed sqlite for php5, then I ran the php artisan migrate command again and worked perfectly.
这为php5安装了sqlite,然后我再次运行php artisan迁移命令并运行良好。
#3
13
You need to specifically enable the pdo_mysql plugin. Assuming you're using a standard PHP installation, then generally you would simply need to add this to your PHP.ini file:
您需要特别启用pdo_mysql插件。假设您正在使用一个标准的PHP安装,那么通常您只需要将它添加到PHP中。ini文件:
extension=pdo_mysql.so
You need to ensure that this file exists in the extension directory though.
您需要确保这个文件存在于扩展目录中。
Adding pdo_pgsql.so
doesn't help because that is for PostgreSQL.
添加pdo_pgsql。这对PostgreSQL没有帮助。
Additionally, you should ensure that you restart the web-server after you make the changes to the PHP ini file, as the changes may not be reflected otherwise.
此外,您应该确保在对PHP ini文件进行更改后重新启动web服务器,否则这些更改可能不会被反映出来。
#4
6
Ran into the same issue here, and turns out this is because PHP at the command line uses a different php.ini
file from the browser version, which is why it looks like it's loading the extension correctly when you look at phpinfo()
in a browser.
这里遇到了同样的问题,这是因为命令行中的PHP使用了不同的PHP。来自浏览器版本的ini文件,这就是为什么当您在浏览器中查看phpinfo()时,看起来它正在正确地加载扩展名。
As per this answer, you just need to run:
根据这个答案,你只需要运行:
php --ini
At the command line, which will tell you the path to the currently loaded php.ini
(probably actually a php-cli.ini
file located in the same place as your regular php.ini
file).
在命令行,它将告诉您当前加载的php的路径。ini(可能实际上是一个php-cli)。ini文件位于与常规php相同的位置。ini文件)。
Once you've found that, modify it with the pdo extensions you want (in this case for MySQL):
找到之后,用你想要的pdo扩展来修改它(在本例中是MySQL):
extension=pdo_mysql.so
Or, for any other users that are on Windows using some kind of WAMP server, it probably looks like this instead:
或者,对于使用某种WAMP服务器的其他Windows用户来说,它可能是这样的:
extension=php_pdo_mysql.dll
#5
6
I think you missed the mysql driver for php5. Execute below command:
我想你错过了php5的mysql驱动。执行下面的命令:
sudo apt-get install php5-mysql
/etc/init.d/php5-fpm restart
#6
4
Please check your Laravel .env
file also. Make sure DB_CONNECTION=mysql
, otherwise it won't work with MySQL. It tried to load something else.
请检查您的Laravel .env文件。确保DB_CONNECTION=mysql,否则它不能使用mysql。它试图加载其他东西。
#7
2
Had the same issue and just figured, website is running under MAMP's php, but when you call in command, it runs mac's(if no bash path modified). you will have issue when mac doesn't have those extensions.
有同样的问题,并且刚刚发现,网站在MAMP的php下运行,但是当您调用in command时,它会运行mac的(如果没有修改bash路径)。当mac没有这些扩展时,你会有问题。
run php -i to find out loaded extensions, and install those one you missed. or run '/Applications/MAMP/bin/php/php5.3.6/bin/php artisan {your command}' to use MAMP's
运行php -我来查找已加载的扩展,并安装那些您错过的扩展。或者运行'/ application /MAMP/bin/php/php5.3.6/bin/php artisan '来使用MAMP'
#8
2
I was also getting the same error --> "[PDOException]
could not find driver "
我也得到了相同的错误——>“[PDOException]找不到驱动程序”
After that I used many commands but not didn't get any help
在那之后,我使用了许多命令,但没有得到任何帮助。
Finally I used the following command, which solved my problem.
最后我使用了下面的命令,它解决了我的问题。
sudo apt-get install php5-sqlite
sudo apt-get安装php5-sqlite
#9
2
Laravel Testing with sqlite needs php pdo sqlite drivers
使用sqlite进行Laravel测试需要php pdo sqlite驱动程序
For Ubuntu 14.04
对于Ubuntu 14.04
sudo apt-get install php5-sqlite
sudo service apache2 restart
In ubuntu 16.04 there is no php5-sqlite
在ubuntu 16.04中没有php5-sqlite
sudo apt-get install php7.0-sqlite
sudo service apache2 restart
#10
2
You are missing a PDO driver.
你少了一个PDO司机。
First install the driver
第一次安装驱动程序
For ubuntu: For mysql database.
ubuntu: mysql数据库。
sudo apt-get install php5.6-mysql/php7.2-mysql
sudo apt-get安装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
sudo apt-cache搜索drivername
Then Run the cmd php artisan migrate
#11
1
I'm unsing ubuntu 14.04
我爹妈ubuntu 14.04
Below command solved this problem for me.
下面的命令为我解决了这个问题。
sudo apt-get install php-mysql
sudo apt-get安装php mysql
In my case, after updating my php version from 5.5.9 to 7.0.8 i received this error including two other errors.
在我的例子中,在将php版本从5.5.9更新到7.0.8之后,我收到了这个错误,包括另外两个错误。
errors:
错误:
-
laravel/framework v5.2.14 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
laravel/framework v5.2.14需要ext-mbstring * ->请求的PHP扩展mbstring从您的系统中丢失。
-
phpunit/phpunit 4.8.22 requires ext-dom * -> the requested PHP extension dom is missing from your system.
phpunit/phpunit 4.8.22要求ext-dom * ->请求的PHP扩展dom从系统中丢失。
-
[PDOException]
could not find driver找不到司机
Solutions:
解决方案:
I installed this packages and my problems are gone.
我安装了这个包,我的问题消失了。
sudo apt-get install php-mbstring
sudo apt-get安装php-mbstring
sudo apt-get install php-xml
sudo apt-get安装php xml
sudo apt-get install php-mysql
sudo apt-get安装php mysql
#12
1
You must be installing the latest version of php mysql
in my case I am install php7.1-mysql
你一定在安装最新版本的php mysql,在我的例子中,我正在安装php7.1-mysql
Try this
试试这个
sudo apt-get install php7.1-mysql
I am using the latest version of laravel
我正在使用最新版本的laravel
#13
0
For future searchers. On FreeBSD try the next
未来的搜索。在FreeBSD尝试下一个
pkg_info | grep php5-pdo_mysql
if you see the empty line in return do the following:
如果你看到回车的空行,做以下事情:
cd /usr/ports/databases/php5-pdo_mysql
and the do the install
然后做安装
make install clean
then simply restart your apache and you are done
然后简单地重新启动apache,就完成了
e.g. sudo /usr/local/etc/rc.d/apache22 restart
例如:sudo /usr/local/etc/rc.d / apache22重启
#14
0
Install it via this command
通过这个命令安装它
sudo apt-get install php5-gd
sudo apt-get安装php5-gd
this worked for me.
这为我工作。
#15
0
In my case I wasn't aware that the PHP run by Apache was different from the one run by CLI. That might be the case if during configuration in httpd.conf you specified a PHP module, not being the default one your CLI uses.
在我的例子中,我不知道Apache运行的PHP与CLI运行的PHP不同。这可能是在httpd配置期间发生的情况。如果您指定了一个PHP模块,而不是CLI使用的默认模块。
#16
0
I found the proper solution for this error! Either you don't have any database installed or your default database in this file config/database.php is set to some other database like this
我找到了这个错误的正确答案!在这个文件配置/数据库中没有安装任何数据库或默认数据库。php被设置为类似这样的其他数据库
'default' => 'sqlite',
'default' => env('DB_CONNECTION', 'sqlite'), //laravel 5.2
change the default to which one you have installed or install that database which is made to be default! I had installed mysql and php artisan migrate worked after i changed that line to this:
更改已安装的默认数据库,或安装默认数据库!我已经安装了mysql和php artisan,在我将这一行改为:
'default' => 'mysql',
'default' => env('DB_CONNECTION', 'mysql'), //laravel5.2
#17
0
I was also getting the same error --> "[PDOException] could not find driver "
我也得到了相同的错误——>“[PDOException]找不到驱动程序”
I realized that the php was pointing to /usr/bin/php instead of the lampp /opt/lampp/bin/php so i simply created and alias
我意识到php指向的是/usr/bin/php而不是lampp/ opt/lampp/bin/php,所以我创建了别名
alias php="/opt/lampp/bin/php"
别名php = " / opt / lampp / bin / php”
also had to make update to the .env file to ensure the database access credentials were updated.
还必须对.env文件进行更新,以确保更新数据库访问凭据。
And guess what, it Worked!
你猜怎么着,成功了!
#18
0
I had this problem on debian. The issue was, I was using the dotdeb repository for more recent PHP packages. For some reason, it updated the php cli to 7.0, while the web php binary remained php 5.6. I used this answer to link the php command line binary to the 5.6 version, like so:
我在debian上遇到了这个问题。问题是,我正在使用dotdeb存储库来处理更近期的PHP包。出于某种原因,它将php cli更新为7.0,而web php二进制文件仍然是php 5.6。我使用这个答案将php命令行二进制代码链接到5.6版本,如下所示:
$ sudo ln -sfn /usr/bin/php5 /etc/alternatives/php
#19
0
If you are using Laravel 5.x, and the error is from trying to modify the attributes of a column, it is possible the error comes from a missing pre-requisite.
如果你正在使用Laravel 5。错误来自于试图修改列的属性,错误可能来自于缺少的先决条件。
Try this:
试试这个:
composer require doctrine/dbal
Then try running your migrations.
然后尝试运行您的迁移。
From here: https://laravel.com/docs/master/migrations#modifying-columns
从这里:https://laravel.com/docs/master/migrations # modifying-columns
#20
0
This worked with me:(for pgsql: use 'pgsql' instead of 'mysql')
这对我有帮助:(对于pgsql:使用“pgsql”而不是“mysql”)
Step 1)
步骤1)
sudo apt-get install php-mysql
Step 2)
步骤2)
php artisan config:clear
Step 3)
步骤3)
php artisan config:cache
Step 4)
Then restart your server, and generate key again and migrate it, Its Done
步骤4)然后重新启动服务器,再次生成密钥并迁移它,完成
#1
32
You can use
您可以使用
sudo apt-get install php7-mysql
or
或
sudo apt-get install php5-mysql
or
或
sudo apt-get install php-mysql
This worked for me.
这为我工作。
#2
18
This worked for me:
这工作对我来说:
sudo apt-get install php5-sqlite
This installed sqlite for php5, then I ran the php artisan migrate command again and worked perfectly.
这为php5安装了sqlite,然后我再次运行php artisan迁移命令并运行良好。
#3
13
You need to specifically enable the pdo_mysql plugin. Assuming you're using a standard PHP installation, then generally you would simply need to add this to your PHP.ini file:
您需要特别启用pdo_mysql插件。假设您正在使用一个标准的PHP安装,那么通常您只需要将它添加到PHP中。ini文件:
extension=pdo_mysql.so
You need to ensure that this file exists in the extension directory though.
您需要确保这个文件存在于扩展目录中。
Adding pdo_pgsql.so
doesn't help because that is for PostgreSQL.
添加pdo_pgsql。这对PostgreSQL没有帮助。
Additionally, you should ensure that you restart the web-server after you make the changes to the PHP ini file, as the changes may not be reflected otherwise.
此外,您应该确保在对PHP ini文件进行更改后重新启动web服务器,否则这些更改可能不会被反映出来。
#4
6
Ran into the same issue here, and turns out this is because PHP at the command line uses a different php.ini
file from the browser version, which is why it looks like it's loading the extension correctly when you look at phpinfo()
in a browser.
这里遇到了同样的问题,这是因为命令行中的PHP使用了不同的PHP。来自浏览器版本的ini文件,这就是为什么当您在浏览器中查看phpinfo()时,看起来它正在正确地加载扩展名。
As per this answer, you just need to run:
根据这个答案,你只需要运行:
php --ini
At the command line, which will tell you the path to the currently loaded php.ini
(probably actually a php-cli.ini
file located in the same place as your regular php.ini
file).
在命令行,它将告诉您当前加载的php的路径。ini(可能实际上是一个php-cli)。ini文件位于与常规php相同的位置。ini文件)。
Once you've found that, modify it with the pdo extensions you want (in this case for MySQL):
找到之后,用你想要的pdo扩展来修改它(在本例中是MySQL):
extension=pdo_mysql.so
Or, for any other users that are on Windows using some kind of WAMP server, it probably looks like this instead:
或者,对于使用某种WAMP服务器的其他Windows用户来说,它可能是这样的:
extension=php_pdo_mysql.dll
#5
6
I think you missed the mysql driver for php5. Execute below command:
我想你错过了php5的mysql驱动。执行下面的命令:
sudo apt-get install php5-mysql
/etc/init.d/php5-fpm restart
#6
4
Please check your Laravel .env
file also. Make sure DB_CONNECTION=mysql
, otherwise it won't work with MySQL. It tried to load something else.
请检查您的Laravel .env文件。确保DB_CONNECTION=mysql,否则它不能使用mysql。它试图加载其他东西。
#7
2
Had the same issue and just figured, website is running under MAMP's php, but when you call in command, it runs mac's(if no bash path modified). you will have issue when mac doesn't have those extensions.
有同样的问题,并且刚刚发现,网站在MAMP的php下运行,但是当您调用in command时,它会运行mac的(如果没有修改bash路径)。当mac没有这些扩展时,你会有问题。
run php -i to find out loaded extensions, and install those one you missed. or run '/Applications/MAMP/bin/php/php5.3.6/bin/php artisan {your command}' to use MAMP's
运行php -我来查找已加载的扩展,并安装那些您错过的扩展。或者运行'/ application /MAMP/bin/php/php5.3.6/bin/php artisan '来使用MAMP'
#8
2
I was also getting the same error --> "[PDOException]
could not find driver "
我也得到了相同的错误——>“[PDOException]找不到驱动程序”
After that I used many commands but not didn't get any help
在那之后,我使用了许多命令,但没有得到任何帮助。
Finally I used the following command, which solved my problem.
最后我使用了下面的命令,它解决了我的问题。
sudo apt-get install php5-sqlite
sudo apt-get安装php5-sqlite
#9
2
Laravel Testing with sqlite needs php pdo sqlite drivers
使用sqlite进行Laravel测试需要php pdo sqlite驱动程序
For Ubuntu 14.04
对于Ubuntu 14.04
sudo apt-get install php5-sqlite
sudo service apache2 restart
In ubuntu 16.04 there is no php5-sqlite
在ubuntu 16.04中没有php5-sqlite
sudo apt-get install php7.0-sqlite
sudo service apache2 restart
#10
2
You are missing a PDO driver.
你少了一个PDO司机。
First install the driver
第一次安装驱动程序
For ubuntu: For mysql database.
ubuntu: mysql数据库。
sudo apt-get install php5.6-mysql/php7.2-mysql
sudo apt-get安装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
sudo apt-cache搜索drivername
Then Run the cmd php artisan migrate
#11
1
I'm unsing ubuntu 14.04
我爹妈ubuntu 14.04
Below command solved this problem for me.
下面的命令为我解决了这个问题。
sudo apt-get install php-mysql
sudo apt-get安装php mysql
In my case, after updating my php version from 5.5.9 to 7.0.8 i received this error including two other errors.
在我的例子中,在将php版本从5.5.9更新到7.0.8之后,我收到了这个错误,包括另外两个错误。
errors:
错误:
-
laravel/framework v5.2.14 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
laravel/framework v5.2.14需要ext-mbstring * ->请求的PHP扩展mbstring从您的系统中丢失。
-
phpunit/phpunit 4.8.22 requires ext-dom * -> the requested PHP extension dom is missing from your system.
phpunit/phpunit 4.8.22要求ext-dom * ->请求的PHP扩展dom从系统中丢失。
-
[PDOException]
could not find driver找不到司机
Solutions:
解决方案:
I installed this packages and my problems are gone.
我安装了这个包,我的问题消失了。
sudo apt-get install php-mbstring
sudo apt-get安装php-mbstring
sudo apt-get install php-xml
sudo apt-get安装php xml
sudo apt-get install php-mysql
sudo apt-get安装php mysql
#12
1
You must be installing the latest version of php mysql
in my case I am install php7.1-mysql
你一定在安装最新版本的php mysql,在我的例子中,我正在安装php7.1-mysql
Try this
试试这个
sudo apt-get install php7.1-mysql
I am using the latest version of laravel
我正在使用最新版本的laravel
#13
0
For future searchers. On FreeBSD try the next
未来的搜索。在FreeBSD尝试下一个
pkg_info | grep php5-pdo_mysql
if you see the empty line in return do the following:
如果你看到回车的空行,做以下事情:
cd /usr/ports/databases/php5-pdo_mysql
and the do the install
然后做安装
make install clean
then simply restart your apache and you are done
然后简单地重新启动apache,就完成了
e.g. sudo /usr/local/etc/rc.d/apache22 restart
例如:sudo /usr/local/etc/rc.d / apache22重启
#14
0
Install it via this command
通过这个命令安装它
sudo apt-get install php5-gd
sudo apt-get安装php5-gd
this worked for me.
这为我工作。
#15
0
In my case I wasn't aware that the PHP run by Apache was different from the one run by CLI. That might be the case if during configuration in httpd.conf you specified a PHP module, not being the default one your CLI uses.
在我的例子中,我不知道Apache运行的PHP与CLI运行的PHP不同。这可能是在httpd配置期间发生的情况。如果您指定了一个PHP模块,而不是CLI使用的默认模块。
#16
0
I found the proper solution for this error! Either you don't have any database installed or your default database in this file config/database.php is set to some other database like this
我找到了这个错误的正确答案!在这个文件配置/数据库中没有安装任何数据库或默认数据库。php被设置为类似这样的其他数据库
'default' => 'sqlite',
'default' => env('DB_CONNECTION', 'sqlite'), //laravel 5.2
change the default to which one you have installed or install that database which is made to be default! I had installed mysql and php artisan migrate worked after i changed that line to this:
更改已安装的默认数据库,或安装默认数据库!我已经安装了mysql和php artisan,在我将这一行改为:
'default' => 'mysql',
'default' => env('DB_CONNECTION', 'mysql'), //laravel5.2
#17
0
I was also getting the same error --> "[PDOException] could not find driver "
我也得到了相同的错误——>“[PDOException]找不到驱动程序”
I realized that the php was pointing to /usr/bin/php instead of the lampp /opt/lampp/bin/php so i simply created and alias
我意识到php指向的是/usr/bin/php而不是lampp/ opt/lampp/bin/php,所以我创建了别名
alias php="/opt/lampp/bin/php"
别名php = " / opt / lampp / bin / php”
also had to make update to the .env file to ensure the database access credentials were updated.
还必须对.env文件进行更新,以确保更新数据库访问凭据。
And guess what, it Worked!
你猜怎么着,成功了!
#18
0
I had this problem on debian. The issue was, I was using the dotdeb repository for more recent PHP packages. For some reason, it updated the php cli to 7.0, while the web php binary remained php 5.6. I used this answer to link the php command line binary to the 5.6 version, like so:
我在debian上遇到了这个问题。问题是,我正在使用dotdeb存储库来处理更近期的PHP包。出于某种原因,它将php cli更新为7.0,而web php二进制文件仍然是php 5.6。我使用这个答案将php命令行二进制代码链接到5.6版本,如下所示:
$ sudo ln -sfn /usr/bin/php5 /etc/alternatives/php
#19
0
If you are using Laravel 5.x, and the error is from trying to modify the attributes of a column, it is possible the error comes from a missing pre-requisite.
如果你正在使用Laravel 5。错误来自于试图修改列的属性,错误可能来自于缺少的先决条件。
Try this:
试试这个:
composer require doctrine/dbal
Then try running your migrations.
然后尝试运行您的迁移。
From here: https://laravel.com/docs/master/migrations#modifying-columns
从这里:https://laravel.com/docs/master/migrations # modifying-columns
#20
0
This worked with me:(for pgsql: use 'pgsql' instead of 'mysql')
这对我有帮助:(对于pgsql:使用“pgsql”而不是“mysql”)
Step 1)
步骤1)
sudo apt-get install php-mysql
Step 2)
步骤2)
php artisan config:clear
Step 3)
步骤3)
php artisan config:cache
Step 4)
Then restart your server, and generate key again and migrate it, Its Done
步骤4)然后重新启动服务器,再次生成密钥并迁移它,完成