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.

About Simian Studios

Based at a small studio in South London, I create professional websites that inspire. Sculpting each project from start to finish, I use the latest techniques to build result-driven sites for my clients. Find out more →

Mugaruka & Chimanuka

I’ve adopted Mugaruka and Chimanuka - two Eastern Lowland gorillas in the Democratic Republic of the Congo (DRC). Currently there are only about 3000 of these beautiful primates left on our planet and they face constant dangers, including poaching, the exotic pet trade and more. Read the full story →