Laravel 5.5 can't connect to database - php

I have a larvael and I want it to make it in production. I have a server hosting and database on infomaniak.com.
I have upload all my file and I get a SQL timeout error :
SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from
characters where checked = 1 order by RAND() limit 1)
I have an other Laravel website on infomaniak and don't have this problem. I have check my .env file, my /config/database file and try php artisan config:clear or php artisan cache:clear. I also try to dump DB:connection() and the connection information are right.
I can connect to my homestead database in local and work fine. But when I try to connect to the SAME database than my other website with the same .env file and still have the timeout error.
How can I fix this ? Are there a way to clear another cache ? Completly lost :/
EDIT :
If i try :
if(DB::connection()->getDatabaseName()) {
echo "Yes! successfully connected to the DB: " . DB::connection()->getDatabaseName();
}
The page return Yes! successfully connected to the DB: db_name
EDIT 2 :
I just see my hosting server is in PHP 5.6 but it say that's my website is in PHP 7. Really confusing but maybe this informations is important (have another laravel on this server and works like that)

Your problem is the php version, if you're using laravel 5.5 then your host must have php 7 installed.
See the oficial docs here

Related

MySQL+Laravel: SQLSTATE[HY000] [1045] Access denied for user 'so'#'localhost' but connection data is OK and config cache is cleared

I need help here, because it's driving me crazy. I'm trying to connect to the remote production DB but I'm unable. I have read tons of posts about this that are focusing on the credentials and also running the following commands to clean config that are stored in Laravel cache:
php artisan cache:clear
php artisan config:cache
php artisan config:clear
Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Any of these are working for me.
I have checked very well the credentials both in my .env file and my database.php. I'm able to connect to a local database by using the ip "127.0.0.1" but I'm unable with the production DB stored in Google Cloud. It's good to mention that my local IP is allowed to access that Database and I'm able to connect by using MySql Workbench.
Here is what I see when I perform "php artisan tinker" and then "DB::connection()->getPdo();" to check my connection from terminal:
The only thing that calls my attention is the message containing "so#localhost" when I'm not performing a connection to localhost but I don't know if that's related with the issue.
Any other suggestion? I have lost too much time trying to find out what could be happening.
EDIT 1: Laravel Framework 5.8.38
After two days fighting with this one, I readed tons of posts and a lot of unuseful solutions I have found my solution by looking at this video.
Basically, you must stop you XAMPP MySQL Server and open C:\xampp\mysql\bin\my.ini and edit by adding the following command "skip-grant-tables" after the [mysqld] attribute. The result in this file might look this way:
# The MySQL server
default-character-set=utf8mb4
[mysqld]
skip-grant-tables
socket="C:/xampp/mysql/mysql.sock"
...
After that, I ran "php artisan tinker" and DB::connection()->getPdo(); and everything was connected again, but it's good if you first clean your cache and config.

Laravel 6 database connection error. Access denied for user

Couldn't connect to the database with laravel 6.0
SQL user and password were working fine and running smoothly on other project but the same credentials are not working on laravel 6.
I have created another user and give it all permissions but still got the same error.
I had cleared all kind of laravel cache,
remove the bootstrap and storage cache but nothing happened.
Please help me to solve this problem.
OS version: ubuntu 18.04
Server: nginx
Database: mysql 5.7.28
PHP: 7.2
Sharp(#) character recognizes as comment in .env file.
So you should put your password in double quotes("")
like this:
DB_PASSWORD="xfs#sds"

Artisan migrate command no output

I'm trying to setup already made project but I'm stuck at the migrating the DB. I'm using Laravel (5.6.34) on PHP 7.2.9, and MySQL (8.0.12). If I try to run php artisan migrate command I'm getting no output, command stays "active" but nothing happens, no errors.
I tried making fresh project, adding migration and running the same command, same thing. I noticed that all other (or at least bunch of them I tried) artisan commands are working but only migrate one doesn't.
.env info is correct and mysql is up and running.
Any help is appreciated.
Thank you!
Try the following;
1. Check your migration files for content.
2. Flush config with php artisan config:clear
3. Check if database is connected using tinker. Run php artisan tinker then paste in this code; DB::connection()->getPdo();
4. If PDO object is returned, your app is connected to the database. If not and PDOException with message 'SQLSTATE[HY000] [2002] Connection refused' is returned then mysql is not running. If database does not exist, you get the error PDOException with message 'SQLSTATE[HY000] [1049] Unknown database [your_db].
Assigning the password to DB User solved this issue for me (be sure populate DB_PASSWORD inside .env)
mysqladmin -u YOURDBUSER password 'newpassword'

Upload Local Laravel Project to Server

I've created a Laravel 5.3 project on my local apache server(XAMPP) and it works fine with login and registration.
However, when I upload(via FTP) to my server(the server is 000webhosting) and try to do login it returns an error saying:
PDOException in Connector.php line 119:
SQLSTATE[HY000] [2002] Connection refused
I've already changed the .env to match the server DB's info, and just in case I also changed the config/database.php to also match. But it still appears like that?
Do you know exactly everything I have to change in my project so it can work on the server?
May be Your database password changed in live. update .env file

Laravel 5.1 migrate database to hosted mysql

How would I go about doing this (the title is the question), I've changed all my ENV files to my hosted mysql details. When i run php artisan migrate from composer I get the
"denied username#localhost using password yes error".
I've changed the port and everything but I'm not sure what to do anymore and I'm 99% sure that the details are correct I've tried them multiple times
You need check somethings:
are credentials valid (username, password and host)?
the database host is accessible by your application server?
.env file is correctly configured or have some config hard coded in app/config/database.php?
To validade connection, you can try this: http://www.w3schools.com/php/php_mysql_connect.asp
About configuration and enviroments : https://laravel.com/docs/5.2/configuration

Categories