Hedge
Hedge

Reputation: 16768

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

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?

Upvotes: 1

Views: 1464

Answers (2)

zeckdude
zeckdude

Reputation: 16173

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.

Upvotes: 3

c-griffin
c-griffin

Reputation: 3026

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

Upvotes: 0

Related Questions