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

homestead - laravel php artisan migrate 报错

WBOY
Release: 2016-06-06 20:27:36
Original
1311 people have browsed it

我执行

<code>php artisan migrate
</code>
Copy after login
Copy after login

报错

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

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

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

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

<code>DB_HOST=localhost</code>
Copy after login
Copy after login

另外此命令也无效

<code>php artisan migrate --env=production</code>
Copy after login
Copy after login

回复内容:

我执行

<code>php artisan migrate
</code>
Copy after login
Copy after login

报错

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

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

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

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

<code>DB_HOST=localhost</code>
Copy after login
Copy after login

另外此命令也无效

<code>php artisan migrate --env=production</code>
Copy after login
Copy after login

已解决

修改 database.php

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

更新:

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template