Hi! I'm currently reworking my site, so although this content is still online things may change or look odd. Please get in touch to find out how I can help you!

Laravel Artisan migrations not working? Try this…

Just a quick post here with a tip that may help you if, like me, you’re struggling getting Laravel’s php artisan migrate command to work.

In my case I was receiving no output whatsoever - no error messages, no logs - and my app was able to write to the database so I knew the credentials were correct, which made the problem very hard to diagnose.

On a hunch I decided to try setting the socket manually as other people using MAMP have had success with it, and thankfully that solved the problem, despite my not receiving the same error message.

So, my .env now has an extra line:

DB_UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

and my config/database.php has an extra element added to the MySQL settings array:

'unix_socket' => env('DB_UNIX_SOCKET', ''),

Those two additions tell Laravel to look in .env for a defined socket, or to leave the socket empty if one isn’t defined, which triggers the default DSN generation behaviour in the MySqlConnector class.

For me, this doesn’t affect the functionality of my app but does make the migrations work. Running the socket setting through .env means it can easily be modified on a per-machine basis without having to worry about source control etc.

Hope this helps someone avoid wasting a lot of time like I did!

Tags: Development Laravel PHP

Feedback

Sorry, feedback is now closed on this post, but please feel free to get in touch if you would like to talk about it!

Or find posts by tag →

Friends & Influences

  1. Aching Brain
  2. Andy Budd
  3. Anthony Killeen
  4. Ben Everard
  5. Cameron Moll
  6. Dan Cederholm
  7. Dan Mall
  8. Dave Shea
  9. Elliot Jay Stocks
  10. Jamie Knight
  11. Jamie Rumbelow
  12. Jason Santa Maria
  13. Jeff Croft
  14. Jeffrey Zeldman
  15. Jeremy Keith
  16. Jon Hicks
  17. Khoi Vinh
  18. Mark Boulton
  19. Matt Croucher
  20. Nocturnal Monkey
  21. Sarah Parmenter
  22. Shaun Inman
  23. Simon Collison
  24. Tim Van Damme
  25. Toby Howarth