mohdsharique68@gmail.com's avatar

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `sessions` where `id` = yeejiKS4mNhZbn7ESX1fJH0HQbWyk2MdPkF8ITun limit 1)

I did update my existing project on plesk server and getting this error. same project working fine at local server in my PC

0 likes
20 replies
Tray2's avatar

Try restarting the database server. Then make sure that you have the correct ports, ip.addresses and credentials. Also make sure that the database exists and the user you are trying to log in with exists.

mohdsharique68@gmail.com's avatar

this is not database error, bcoz i try to open static page there is no database connection but still get same error

Tray2's avatar

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from sessions where id = yeejiKS4mNhZbn7ESX1fJH0HQbWyk2MdPkF8ITun limit 1)

That is a database error.

You are using a database session driver.

Tray2's avatar

Your .env would be a good place to start.

mohdsharique68@gmail.com's avatar

DB_CONNECTION=mysql DB_HOST=127-0-0-1 DB_PORT=3306 DB_DATABASE=bsf DB_USERNAME= user DB_PASSWORD=#######

this is my database connections

Tray2's avatar

Can you log in with those from a terminal window?

mysql -uuser -p
Tray2's avatar

On the plesk server can you connect to the database from the command line?

Does the database reside on localhost on the plesk server?

mohdsharique68@gmail.com's avatar

i did not try connecting plesk server database from the command line.. i did create database manually and import tables from local database

Tray2's avatar

It's most likely that you have something wrong in your database setup.

Make sure that you have the correct hostname/ip, correct credentials, correct port and correct database name.

mohdsharique68@gmail.com's avatar

can you tell me how i can deploy Laravel project on server and what configure i have to change for database

Tray2's avatar

You need to make sure you use the correct database driver. probably MySQL You need to have the correct hostname/ip-address and port for the MySQL server probably 127.0.0.1 and 3306. Then you need to make sure you have the correct username and password. Lastly you need to have the correct database name.

After that you need to migrate the database.

Sloarot's avatar

Solution that worked for me: before doing 'php artisan serve', do 'php artisan migrate', this is NOT specified in the 'Installation' part of the documentation, they only mention it a few lines later under database configuration.

When I did this, it worked (at least for me). And I've had MANY errors the last couple of days ... am really starting to get tired of having tons of errors (Vite this, php version that, change js to cjs, can't find page etc) BEFORE even getting to the basic laravel starting page. I'd really like to suggest development team to create a bullet proof installation package. You can shoot me on this but Wordpress in that regard is a 1000 times better.

Yesterday I completely went on a tangent for the first installation because of this, and lost two-three hours just to get a basic installation with Breeze. I'm not an expert, sure, but jeezes how hard can it be to just have a basic installation that WORKS every time. I've tried a few months ago when they recommended Laragon and it was the same thing, took ages to get it to work....

440music's avatar

I use Plesk web server and haven't had any issues with laravel11 First check to ensure the user has access to the database.

Then in the website control panel select Laravel or Get Started Now select Laravel and you're in the control panel for the list below. You'll get along better with Plesk if you use the control panel.

Now the menu will have these options

Dashboard

Artisan

Composer

Node.js

Deployment

Scheduled Tasks

Queue

Select Artisan and in the text field write your commands, Plesk assumes php artisan and just like using the web based command line, use it just like the terminal and the results will display in the results box

I have Apache on a few sites, Nginx on a couple and I'm converting my website to Laravel

zemlaka2's avatar

@sloarot moto x3m How can new Laravel users effectively troubleshoot errors related to database migrations and dependencies during the initial setup process to save time and avoid frustration?

Tray2's avatar

@zemlaka2 Please ask your question in a new thread.

However it is not hard to setup and configure the database. There are multiple guides for this depending o your choice of hosting.

I just googled "laravel on aws" and this was the first non sponsored result

https://medium.com/@elijah_williams_agc/laravel-and-aws-deploying-laravel-applications-on-amazon-web-services-4e4e025e5dd4

All you really have to do is make sure the database name, the username and password, the host and port are correct in your .env file.

If you have ran any kind of artisan cache or optimize command in your dev environment (You neer should), you need to clear the cache, and recache it.

Please or to participate in this conversation.