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.
As of Laravel 5 the database username and password goes in the .env file that exists in the project directory, e.g.
As you can see these environment variables are overriding the 'forge' strings here so changing them has no effect:
More information is here https://mattstauffer.co/blog/laravel-5.0-environment-detection-and-environment-variables
I ran into this problem when running PHPUnit in Elixir/Gulp, and Homestead as my Vagrant enviroment.
In my case I edited the .env file from
DB_HOST=localhost
toDB_HOST=192.168.10.10
where192.168.10.10
is the IP of my Vagrant/Homestead host.If anyone are still looking for the answer, just check your .env file. For some reason laravel create a .env.example file, so all this answers didn't work for me. I fixed my issue renamming .env.example to .env
Building on the answer from @dcarrith ...
Instead of editing the config files, I created an alias in the location that PHP is looking that connects to the real mysql.sock. (source)
Just run these two commands (no restart needed):
In may case, I'd simply used
instead of
for my forge larval setup using homestead. I'm assuming this meant the site was getting served, but the MySQL server wasn't ever booted. When I used the latter command to launch my vagrant box, the error went away.
The error message indicates that a MySQL connection via socket is tried (which is not supported).
In the context of Laravel (artisan), you probably want to use a different / the correct environment. Eg:
php artisan migrate --env=production
(or whatever environment). See here.