Artisan-commands need different hostname in db-config than Laravel itself

情到浓时终转凉″ 提交于 2020-01-16 18:41:52

问题


This is a strange one I've never been able to solve ever since I started using Laravel.

When I issue artisan-commands like 'php artisan migrate' in my db-config (I'm using MySQL via MAMP) the host line has to be:

'host' => 'localhost:8889',

However when loading a page in the web-browser I get:

SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:8889'

It magically works when I change it to:

'host' => 'localhost',

On the live-server I'm running the application on I don't have this problem. What is going wrong here?


回答1:


This is most likely happening because you just cd'd into the directory using Terminal and ran the php artisan migrate command from there. You'll need to ssh into your vagrant box using vagrant ssh, then navigate to your project folder and run the migrate command from there.




回答2:


What port is your MySQL server running on locally? By default, MySQL looks for a server on :3306, so you'll get the error unless something is there to serve it or re-direct it

My guess is the prod server is running MySQL on :8889 and your local environment is running MySQL on :3306

In your local environment, You could either change the port to 8889:
http://www.mamp.info/en/documentation/#q11

Or forward the port:
http://www.chrisvanpatten.com/port-forwarding-mavericks



来源:https://stackoverflow.com/questions/25331155/artisan-commands-need-different-hostname-in-db-config-than-laravel-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!