Laravel Illuminate\Database\QueryException (No such file or directory) when using the command "php artisan migrate"
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
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:
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.1usually works, sometimes usinglocalhostcan 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) andDB_PASSWORDare 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:
- Log into MySQL: SSH into your VPS and connect directly to the MySQL shell:bash
sudo mysql -u root -p - Verify Database: Inside the MySQL prompt, check if the database exists:sql
SHOW DATABASES; - Create Database (If Necessary): If the
laraveldatabase does not exist, create it immediately:sqlCREATE DATABASE laravel; - Verify User Permissions: Ensure the user specified in your
.envhas 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: