Setting up Laravel on a Mac php artisan migrate error: No such file or directory

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Troubleshooting Laravel Migrations on Mac: Resolving Errors with "No such file or directory" Body:
  1. Pulling a Laravel Project from Git to Mac: You've successfully pulled a working Laravel project from Git into your Mac machine using MAMP. The project was running smoothly on a Linux-based system, which means the code should work with minor adjustments for the Mac environment.
  2. Initial Commands: You ran the commands 'composer install' and then 'php artisan migrate'. This is the correct approach to install all dependencies required by your Laravel project and run database migrations.
  3. Error Encountered: Unfortunately, you encountered an error while running 'php artisan migrate', which indicated that a [PDOException] with SQLSTATE[HY000] [2002] No such file or directory. This usually happens when Laravel is unable to locate the database connection.

Diagnosing and Resolution:

  1. Check PHP Version and MySQL Setup: Verify that your PHP version is 5.5 or higher, as Laravel might require a newer version for its functionalities. Ensure that the MySQL server on your Mac is set up correctly with the proper installation of XAMPP. Run 'php -v' from the terminal to check your PHP version and 'mysql -v' to verify the MySQL version.
  2. Investigate Database Configurations: Review your database configuration in Laravel. This can be found within the config/database.php file. Ensure that the host, username, password, and other database connection details are correct for your local environment. You might also need to replace 'localhost' with the IP address of the MAMP server.
  3. Check PHP.ini and Database Socket: As suggested by the user in the edit, you can try adding these lines in php.ini: mysql.default_socket=/var/run/mysqld/mysqld.sock; mysqli.default_socket=/var/run/mysqld/mysqld.sock; pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock Also, create the symlink /var/mysql and set up a symbolic link as sudo mkdir /var/mysql && cd /var/mysql && ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock However, if this does not resolve the issue, try using php artisan migrate --force to overwrite existing tables.
  4. Updating Laravel Version: As a last resort, ensure that you are using the latest available version of Laravel and that it is compatible with your PHP and MySQL versions. If necessary, update both the framework and database server to ensure they work seamlessly together.
  5. Seeking Further Assistance: If you've tried all these troubleshooting measures but still encounter the issue, consider reaching out for support from the Laravel community or seeking professional assistance. You can refer to https://laravelcompany.com/for-web-developers/laravel-expertise for expert guidance and assistance with your Laravel development needs.

Conclusion:

By following these steps, you should be able to troubleshoot and resolve the "No such file or directory" error when running 'php artisan migrate' in a Laravel project on your Mac. Don't forget to use best practices, such as updating PHP and MySQL versions, ensuring correct configuration files, and seeking expert assistance if needed. Happy coding!