Laravel Illuminate\Database\QueryException (No such file or directory) when using the command "php artisan migrate"

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Solving the Mystery: Laravel `QueryException` During `php artisan migrate` on a VPS As a senior developer, I’ve seen countless deployment headaches. One of the most frustrating errors developers encounter when setting up a Laravel application on a remote server is the `Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] No such file or directory` error when attempting to run `php artisan migrate`. This post will dissect this specific error, examine why it occurs even when your `.env` and database configuration seem correct, and provide a comprehensive troubleshooting guide tailored for VPS environments. We will also look at the context of your provided setup to ensure your Laravel deployment is solid. ## Understanding the Error: What is `No such file or directory` in SQL? The error message you are seeing—specifically the part pointing to querying `information_schema.tables` for the `migrations` table—is not a generic PHP error; it's a direct signal from your MySQL server indicating that the database connection, while established, failed to locate the specific structure Laravel expects. In layman's terms: Laravel successfully connected to the MySQL server (it knows how to talk to the host and port), but when it tried to execute the necessary command to check for existing migration records (`SELECT * FROM information_schema.tables...`), the database reported that the required schema or table structure simply did not exist in the context where Laravel was looking. This almost always points to a problem with **database permissions, the existence of the target database, or an incorrect connection setting**, rather than an issue with the migration files themselves. ## Troubleshooting Steps for VPS Deployments Since you are running this on a VPS via SSH, the troubleshooting steps must focus heavily on the server-side configuration and MySQL service health. ### 1. Verify Database Connection Integrity The first step is to confirm that the connection parameters in your `.env` file precisely match what the MySQL server expects. Reviewing your provided environment variables: ```dotenv DB_CONNECTION=mysql DB_HOST=127.0.0.1 # Or 'localhost' DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= ``` **Actionable Checks:** * **Host Check:** While `127.0.0.1` usually works, sometimes using `localhost` can resolve subtle differences depending on the PHP/MySQL setup. Ensure the MySQL server is listening on the expected interface. * **Credentials Validation:** Confirm that the `DB_USERNAME` (`root`) and `DB_PASSWORD` are correct for the database user accessing the MySQL instance. A password mismatch is a frequent, silent killer of connection attempts. ### 2. Check Database and Table Existence The error explicitly references the `laravel` schema/database. You must ensure this database exists *before* running migrations. **Actionable Checks:** 1. **Log into MySQL:** SSH into your VPS and connect directly to the MySQL shell: ```bash sudo mysql -u root -p ``` 2. **Verify Database:** Inside the MySQL prompt, check if the database exists: ```sql SHOW DATABASES; ``` 3. **Create Database (If Necessary):** If the `laravel` database does not exist, create it immediately: ```sql CREATE DATABASE laravel; ``` 4. **Verify User Permissions:** Ensure the user specified in your `.env` has full privileges over this newly created database. ### 3. Addressing Potential Laravel Setup Issues If the connection and permissions are confirmed correct, consider these final steps often missed in remote setups: