Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Problem accessing database with sail

Hello,

Here is my docker-compose file.

And here the .env file

DB_CONNECTION=mariadb
DB_HOST=mariadb
DB_PORT=3306

I can connect to the phpmyadmin and access the database without trouble.

But I get this error message in the logs when I load the page on the browser.

[2025-06-22 21:50:00] local.ERROR: SQLSTATE[HY000] [2002] No such file or directory (Connection: mariadb, SQL: delete from cache where key in (illuminate:schedule:interrupt, illuminate:cache:flexible:created:illuminate:schedule:interrupt)) {"exception":"[object] (Illuminate\Database\QueryException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory (Connection: mariadb, SQL: delete from cache where key in (illuminate:schedule:interrupt, illuminate:cache:flexible:created:illuminate:schedule:interrupt)) at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825)

Do you have any idea why ?

I'm searching for the solution for a pair of hours without auccess.

Thanks for your help.

V

0 likes
2 replies
LaryAI's avatar

Certainly! The error message:

SQLSTATE[HY000] [2002] No such file or directory (Connection: mariadb, SQL: ...)

means that your Laravel app inside the laravel.test container cannot connect to the MariaDB server using the configured settings.

Key points:

  • You can access the database via phpMyAdmin, so MariaDB is running and accessible from outside the container.
  • Your .env is set to:
    DB_CONNECTION=mariadb
    DB_HOST=mariadb
    DB_PORT=3306
    

Solution Steps

1. Use the Correct DB_CONNECTION

Laravel's default database drivers are: mysql, pgsql, sqlite, sqlsrv.
There is no built-in mariadb driver.
You should use mysql as the connection type, even if you are running MariaDB.

Change your .env to:

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306

2. Rebuild and Restart Sail

After changing .env, restart your containers to ensure the new environment variables are loaded:

./vendor/bin/sail down
./vendor/bin/sail up -d

3. Check Database Credentials

Make sure that the values for DB_DATABASE, DB_USERNAME, and DB_PASSWORD in your .env match those in your docker-compose.yml under the mariadb service.

Example:

DB_DATABASE=your_db
DB_USERNAME=your_user
DB_PASSWORD=your_password

And in docker-compose.yml:

environment:
  MYSQL_DATABASE: '${DB_DATABASE}'
  MYSQL_USER: '${DB_USERNAME}'
  MYSQL_PASSWORD: '${DB_PASSWORD}'
  MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'

4. Clear Config Cache

Sometimes Laravel caches the config. Run this inside your Sail container:

./vendor/bin/sail artisan config:clear

5. Test the Connection

Try running a migration to test the connection:

./vendor/bin/sail artisan migrate

Summary

Your main issue is using DB_CONNECTION=mariadb. Change it to mysql.

Final .env example:

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=your_db
DB_USERNAME=your_user
DB_PASSWORD=your_password

Let me know if you still have issues after making these changes!

vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

It was only a cache problem.

I don't know why, I never cache the configuration in development mode. Probably I cached the configuration for any reason and I had this problem today.

Please or to participate in this conversation.