Rumah  >  Artikel  >  pembangunan bahagian belakang  >  homestead - laravel php artisan migrate 报错

homestead - laravel php artisan migrate 报错

WBOY
WBOYasal
2016-06-06 20:27:361259semak imbas

我执行

<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

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn