You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Homestead环境下Laravel项目MySQL迁移问题:仅能通过Vagrant SSH执行php artisan migrate

Fixing Laravel Migrate Error: Works in Homestead SSH, Fails on Local Terminal

Hey Sergio, I’ve run into this exact issue with Homestead before—let’s break down why this is happening and how to fix it quickly.

Why the Local Terminal Fails

When you run php artisan migrate locally, your .env is set to DB_HOST=localhost and DB_PORT=33060. Here’s the core problem:

  • On your local machine, localhost often tries to connect via a UNIX socket instead of the TCP port you’ve mapped (33060) to Homestead’s MySQL.
  • Inside Homestead SSH, localhost points directly to the virtual machine’s MySQL instance (which listens on port 3306 natively), so the connection works without extra hoops.

Step-by-Step Fixes

1. Update Your .env Database Host

Change DB_HOST=localhost to DB_HOST=127.0.0.1. This forces your local terminal to use a TCP connection instead of a socket, which plays nice with Homestead’s port mapping:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=db_corsi
DB_USERNAME=homestead
DB_PASSWORD=secret

2. Verify Homestead Port Mapping

Double-check your Homestead.yaml file to ensure the MySQL port mapping exists. It should include this block:

ports:
    - send: 33060
      to: 3306

If you added or modified this, reload Homestead to apply the changes:

vagrant reload --provision

3. Clear Laravel’s Configuration Cache

Laravel might be holding onto old cached config values, so clear them locally to make sure your updated .env settings take effect:

php artisan config:clear

4. Test the Connection Manually (Optional)

To confirm your local machine can reach the Homestead MySQL instance, run this MySQL command:

mysql -h 127.0.0.1 -P 33060 -u homestead -psecret db_corsi

If you get a MySQL prompt, the connection is working—your artisan migrate command should now run successfully locally.


内容的提问来源于stack exchange,提问作者SergioDe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 17:37:43