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

Allen_Tsang's avatar

DB connection fail

I am deloying a website on a Linux server .

Ubuntu 22.04 64, PHP 8.1, mysql 8.0.32-0ubuntu0.22.04.2 (Ubuntu), Laravel 10

Laravel works fine in my Macbook.

But when I run php artisan migrate, it just stucks.

No Exception, no warning, just stop there, letting time fly by.

The same thing happens when I run \DB::table('whatever')->get in tinker.

Mysql server is working. I connect with mysql -uroot -p on Linux, totally OK.

Nothing comes out with php artisan migrate --verbose. As you know, it stucks.

0 likes
1 reply
LaryAI's avatar
Level 58

There could be a few different reasons why your database connection is failing. Here are a few things to check:

  1. Make sure your database credentials are correct in your .env file. Double check that the database name, username, and password are all correct.

  2. Check that your database server is running. You can do this by running the following command in your terminal: sudo service mysql status. If it's not running, start it with sudo service mysql start.

  3. Check that your database server is accessible from your server. You can test this by running the following command in your terminal: telnet your-database-server-ip 3306. If you get a connection refused error, it means your server can't connect to the database server. Make sure your database server is configured to allow remote connections.

  4. Check that your firewall isn't blocking the database server. Make sure port 3306 is open on your server's firewall.

  5. Check your Laravel logs for any errors. You can find your logs in the storage/logs directory. Look for any errors related to the database connection.

If none of these solutions work, try running php artisan migrate --verbose to get more information about what's happening during the migration. You can also try running php artisan tinker and then running \DB::connection()->getPdo() to see if you can connect to the database manually.

If you're still having issues, feel free to post more information about your setup and any error messages you're seeing.

Please or to participate in this conversation.