Home  >  Article  >  Backend Development  >  homestead - laravel php artisan migrate 报错

homestead - laravel php artisan migrate 报错

WBOY
WBOYOriginal
2016-06-06 20:27:361257browse

我执行

<code>php artisan migrate
</code>

报错

<code>[PDOException]
  SQLSTATE[HY000] [2002] No such file or directory</code>

我在网上查找了资料,对.envdatabase.php 文件配置都没问题

<code>DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret</code>

其中根据说法修改下面配置为 127.0.0.1 0.0.0.0均无效

<code>DB_HOST=localhost</code>

另外此命令也无效

<code>php artisan migrate --env=production</code>

回复内容:

我执行

<code>php artisan migrate
</code>

报错

<code>[PDOException]
  SQLSTATE[HY000] [2002] No such file or directory</code>

我在网上查找了资料,对.envdatabase.php 文件配置都没问题

<code>DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret</code>

其中根据说法修改下面配置为 127.0.0.1 0.0.0.0均无效

<code>DB_HOST=localhost</code>

另外此命令也无效

<code>php artisan migrate --env=production</code>

已解决

修改 database.php

<code>'host' => env('DB_HOST', 'localhost') . ('homestead' == gethostname() ? null : ':33060'),</code>

更新:

我是在Mac宿主机执行的命令,所以需要指定映射的端口号:33060
如果你直接在homestead虚机中执行是不用指定的,因为默认就是3306

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn