dongsicheng5262 2016-12-25 12:27
浏览 118
已采纳

奇怪的行为Laravel Homestead数据库连接

I am experiencing a peculiar error working with Laravel, Homestead and MySQL. This is the part of my .env file related to the database:

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

If I set the port to 3306 I can access the tables from my application but I cannot execute commands from Terminal such as php artisan migrate. If I set the port to 33060 I can execute commands from Terminal but I cannot access the tables from my application.

  • 写回答

1条回答 默认 最新

  • doutan5844 2016-12-26 00:58
    关注

    Your application is running on the IP provided in Homestead.yaml so when localhost is relative to your application port 3306 works. When running artisan while not SSH into your vagrant vm you are running the command relative to the localhost of your machine, not the vm, so your'e trying to run the migrations against a machine with no database.

    The reason that port 33060 works for your local machine is because Homestead by default forwards this port to your vagrant virtual machines port 3306. But due to your .env now specifying port 33060 the vagrant virtual machine now can not reach port 3306.

    Leave the DB_HOST set to 127.0.0.1 with port 3306 and SSH into your vagrant vm via the vagrant ssh command to run your migration command.

    Or alternatively you could have multiple .env files for your various environments

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程