I believe that I've successfully deployed my (very basic) site to fortrabbit, but as soon as I connect to SSH to run some commands (such as php artisan migrate
or php artisan db:seed
) I get an error message:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
At some point the migration must have worked, because my tables are there - but this doesn't explain why it isn't working for me now.
[This is outdated, database info is stored in .env now] More easier way to solve the issue by is editing the
:)
Change the database configuration here and it should work
If you are using Laravel Homestead, make sure you're calling the commands on the server.
Then simply cd to the right directory and fire your command there.
It is the correct response for me. I disabled the option
pdo_mysql.default_socket
in my php.ini and set the database host at127.0.0.1
.I had the exact same problem. None of the above solutions worked for me. I solved the problem by changing the "host" in the /app/config/database.php file from "localhost" to "127.0.0.1".
Not sure why "localhost" doesn't work by default but I found this answer in a similar question solved in a symfony2 post. https://stackoverflow.com/a/9251924/1231563
Update: Some people have asked as to why this fix works so I have done a little bit of research into the topic. It seems as though they use different connection types as explained in this post https://stackoverflow.com/a/9715164/1231563
The issue that arose here is that "localhost" uses a UNIX socket and can not find the database in the standard directory. However "127.0.0.1" uses TCP (Transmission Control Protocol), which essentially means it runs through the "local internet" on your computer being much more reliable than the UNIX socket in this case.
This is because PDO treats "localhost" host specially:
(from http://php.net/manual/en/ref.pdo-mysql.connection.php)
Changing localhost to 127.0.0.1 will "force" the use of TCP.
Note: mysqli_connect is working fine with localhost.
If you are using Laravel Homestead, here is settings
(include Vagrant-Virtual Machine)
.bash-profile
database.php
Terminal