if you have tinker, you could write config('database') and check if your .env file is being read
If thats not possible (no command line) then put @dd(config('database')) in a view file and then show that view.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I installed Laravel in a shared hosting, I placed all the folders of laravel inside a folder called /site, at the same level of public_html, and the contents of public are in public_html. for now, the routes are working, but is not connecting to the database. in fact, is not paying attention to the .ENV file, I even emptied the password and user and it only gives: SQLSTATE[HY000] [2006] MySQL server has gone away
I also changed the max packets to: SET max_allowed_packet = 1024 * 1024 * 512;
and still is not working.
what could I do to at least get an idea and ask for support to fix this.
if you have tinker, you could write config('database') and check if your .env file is being read
If thats not possible (no command line) then put @dd(config('database')) in a view file and then show that view.
Hi Snapey, I did a dump(config('database')) and got this:
array:4 [▼
"default" => "mysql"
"connections" => array:4 [▼
"sqlite" => array:5 [▶]
"mysql" => array:15 [▶]
"pgsql" => array:12 [▶]
"sqlsrv" => array:10 [▶]
]
So I assume it is actually connecting to the database, right?
Click the little arrow infront of mysql to see what is inside it :)
I did, I can see this, btw, I changed the sensitive data
is thre somewhere what should say is not connected?
array:4 [▼
"default" => "mysql"
"connections" => array:4 [▼
"sqlite" => array:5 [▶]
"mysql" => array:15 [▼
"driver" => "mysql"
"url" => null
"host" => "127.0.0.1"
"port" => "3306"
"database" => "DBNAME"
"username" => "USERNAME"
"password" => "PASSWORD"
"unix_socket" => ""
"charset" => "utf8mb4"
"collation" => "utf8mb4_unicode_ci"
"prefix" => ""
"prefix_indexes" => true
"strict" => true
"engine" => null
"options" => array:1 [▼
20 => true
]
]
"pgsql" => array:12 [▶]
"sqlsrv" => array:10 [▶]
]
"migrations" => "migrations"
"redis" => array:4 [▶]
Ok, I tried checking the connection to the database with:
if(DB::connection()->getDatabaseName()){
echo "conncted sucessfully to database ".DB::connection()->getDatabaseName();
}
and is connecting to the database. but bellow that, when I try to bring anything from the database, it fails with SQLSTATE[HY000] [2006] MySQL server has gone away
"Packets out of order. Expected 0 received 1. Packet size=68"
Could it be that the server sucks completely? how could I find this problem to tell the support guy, because he is saying that there are no problems with the server because other sites are working fine (which are php native)
Could you try creating a simple test.php file in the public folder and make a very simple PDO test?
Something like this.
<?php
$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";
try {
$pdo = new PDO($dsn, $user, $passwd);
$stm = $pdo->query("SELECT VERSION()");
$version = $stm->fetch();
echo $version[0] . PHP_EOL;
} catch(Exception $e) {
echo $e->getMessage();
}
it returns this: 10.2.27-MariaDB
Strange. That seems to work. This might work but I am not sure it is best practice. Open database.php and add this to the options array under mysql
'options' => [
PDO::ATTR_EMULATE_PREPARES => true
],
I did this, then I went to bootstrap/cache/ and changed the names of all the files to manually "delete" the cache. and it created new files: http://i.imgur.com/vCE6Ekz.png
and it still gives me the same error. http://i.imgur.com/Y0cfTMi.png
Do you have any sort of shell access? If so can you then run php artisan cache:clear?
not really, i have shell access but is somewhat limited when I do that command, it returns nothing.
is there a way to do it manually? like deleting files through ftp?
I got someone to clear the cache, and still is giving problems.
Can you show the output of the config('database.mysql') again?
here it is. I modified the dabase, username and password.
array:4 [▼
"default" => "mysql"
"connections" => array:4 [▼
"sqlite" => array:5 [▶]
"mysql" => array:15 [▼
"driver" => "mysql"
"url" => null
"host" => "127.0.0.1"
"port" => "3306"
"database" => "DBNAME"
"username" => "XXX"
"password" => "XXX"
"unix_socket" => ""
"charset" => "utf8mb4"
"collation" => "utf8mb4_unicode_ci"
"prefix" => ""
"prefix_indexes" => true
"strict" => true
"engine" => null
"options" => array:1 [▶]
]
"pgsql" => array:12 [▶]
"sqlsrv" => array:10 [▶]
]
"migrations" => "migrations"
"redis" => array:4 [▶]
]
Oh sorry please press the arrow in front of options
here is the modification I did to the dabase.php
http://i.imgur.com/0O9Igvn.png
array:4 [▼
"default" => "mysql"
"connections" => array:4 [▼
"sqlite" => array:5 [▶]
"mysql" => array:15 [▼
"driver" => "mysql"
"url" => null
"host" => "127.0.0.1"
"port" => "3306"
"database" => "xxx"
"username" => "xxx"
"password" => "xxx"
"unix_socket" => ""
"charset" => "utf8mb4"
"collation" => "utf8mb4_unicode_ci"
"prefix" => ""
"prefix_indexes" => true
"strict" => true
"engine" => null
"options" => array:1 [▼
20 => true
]
]
FINALLY GOT IT WORKING!
to fix it, the config at the .env file was changed from DB_HOST=127.0.0.1 to DB_HOST=localhost
thanks for all of those who helped!
Great to hear. I would suggest telling your provider so that they can tell others with the same issue
Please or to participate in this conversation.