Strange behavior with Laravel Sail: after a restart I need to rebuild - laravel

Strange behavior with Laravel Sail: after a reboot, I need to rebuild with docker-compose build --no-cache
I verify that the container is active, and other apps like TablePlus connect perfectly, although it is true that it does so through 127.0.0.1 in its configuration
Tests\Console\Commands\Tasks\Api\AnalyzerCallsCommandTest::time_and_astro_event_generate_normal_job
Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: nodename nor servname provided, or not known (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
my .env.testing
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=testing
DB_USERNAME=sail
DB_PASSWORD=password
FORWARD_DB_PORT=3306
my .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=sitelight
DB_USERNAME=sail
DB_PASSWORD=password
FORWARD_DB_PORT=3306
With these settings I can access localhost and log in (use database for this action), access MySQL in Tableplus with server 127.0.0.1
On every change run in sail clear all caches and configs.
Workaround
I need to use in every down MacBook run a stop docker, and run sail build --no-cache
Edited at 15/Aut/2022
Workaournd II
After seeing some posts on the internet, y get an ugly solution
$ docker network inspect bridge
...
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
If edit my .env.testing
DB_HOST=172.17.0.1
With this workaround works fine.
But after some time (2 o 3 hours of programming and testing) problem persists with **timeout"
Time: 00:30.131, Memory: 36.50 MB
There was 1 error:
1) Tests\Console\Commands\Tasks\Api\AnalyzerCallsCommandTest::just_one_second_before_first_event_for_analyzer_cron_at_sunset_send_normal_job
Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Operation timed out (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
/Users/abkrim/Sites/sitelight/vendor/laravel/framework/src/Illuminate/Database/Connection.php:759
Of course, at this moment I do some checks:
On table plus work fine connection to MySQL docker
On browser any problem with access to MySQL data

Related

SQLSTATE[HY000] [2002] Connection refused |

I'm using MAC OS and I'm new to laravel .. I'm working on laravel using xampp and when i run the command php artisan migrate
I get this error
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = web and table_name = migrations and table_type = 'BASE TABLE')
my .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=web
DB_USERNAME=root
DB_PASSWORD=
I searched and tried most of the ways and it is still not working unfortunately
Try the methods below:
open your .env file and change DB_HOST = 127.0.0.1 to localhost
try restarting your localhost server (xampp)
try downgrading your xampp to a lower version

php artisan migrate throws received invalid response to SSL negotiation

I have a laravel app on nginx with postresql
php artisan migrate
throws error:
In Connection.php line 671:
SQLSTATE[08006] [7] received invalid response to SSL negotiation: b (SQL: select * from information_schema.tables where table_schema = publ
ic and table_name = migrations and table_type = 'BASE TABLE')
In Connector.php line 70:
SQLSTATE[08006] [7] received invalid response to SSL negotiation: b
FILES:
.env
...
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=secretdbname
DB_USERNAME=secretusername
DB_PASSWORD=secretpassword
...
postresql.conf
...
port = 5432
...
in php.ini enabled:
pgsql
pdo_pgsql
mbstring
php -m
...
mbstring
openssl
PDO
pdo_mysql
pdo_pgsql
pgsql
...
Appropriate db exists, user exists and has got all the privileges.
Postgres service is active.
DB and app are located on the same server.
What I have tried:
setting up a different port in both .env and postgres.conf
tested with a different db, user and password
restarted postresql
in tinker DB::connection()->getPdo(); throws the same error
in DB_HOST tried 127.0.0.1. instead of localhost
in config/database.php i tried setting 'sslmode' to 'disable'
I have SSL certificate with certbot.
I would appreciate some hint on how to solve the above error.
Indeed, following Alex running
php artisan config:cache
helped, as it thrown a slightly different error which pointed me to the actual solution
SOLUTION:
postgresql.conf file has got this line:
listen_addresses = 'localhost'
commented by default, thus the solution is simply to uncomment it (as I mentioned in my original post, both DB and app are on the same server).
Hope it will save sb's time for the future.
I got the same error today with the Laravel 9.
The solution was to make sure the Postgress DB_Port inside .env is pointing to 5432.
Hope it will help others.

Laravel Homestead could not connect to server 127.0.0.1

I have installed laravel homestead and vagrant. After vagrant up my local site started work.
My migrations worked well and i could connect to DB with PhpStorm ( http://joxi.ru/a2X45M1S1x3Vw2 )
my .env file contains the same code as written in doc
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=54320
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
But when I try to register new user I got an error
SQLSTATE[08006] [7] could not connect to server: Connection refused Is
the server running on host "127.0.0.1" and accepting TCP/IP
connections on port 54320?
( http://joxi.ru/nAynW7asYOD39r )
How it possible when migrations run well but connection refused?
Your screenshot says that Laravel is having trouble connecting to 192.168.10.10, which isn't the same as 127.0.0.1. Check that the correct DB_HOST is set in your .env file.
In case the config from the .env file isn't being used, also check the config/database.php file and verify the settings there too.
You have to change .env -> DB_PORT
for pgsql use DB_PORT=5432
I was having this same issue, and what worked for me was to change my DB_HOST=127.0.0.1 to ip: "192.168.56.56"(the same id that is on my Homestead.yaml file).

Laravel Homestead not working database connect

I have installed laravel homestead and run it.
But I can't run migration locally and in vagrant.
If I try to run the migration inside vagrant
cd ~/code/project/
php artisan migrate
I got an error
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 54320?"
If I try to run the migration locally I got a another error
PDOException::("could not find driver")
my .env file contains the same code as written in doc
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=54320
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Maybe something I do not understand but do I need posgresql locally and inside my vagrant? Where I have to work with database locally or with vagrant?

SQLSTATE[HY000] [2002] Connection refused only in browser

I am on OS X Yosemite, running the latest homestead with Laravel 5.3.
I am able to run and reset migration in terminal from OS X. I can see the tables when I connect to the database with Sequel Pro using standard connection. I even see the tables when I SSH into the virtual box and run mysql -uhomestead -psecret.
The problem is, when I try to register a new user from the browser, I get the PDOException in Connector.php line 119: SQLSTATE[HY000] [2002] Connection refused error. It works when I run php artisan serve and fill in the form at http://localhost:8000/register.
I tried changing DB_HOST to 192.168.10.10 but that causes migrations to fail.
I might have created some chaos while trying to install mysql. I installed it using homebrew. Then i ran mysql.server start and at another point I ran brew services start mysql because I was not sure if it was working.
Homestead.yml file:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/code/laravel
to: /home/vagrant/laravel
type: "nfs"
sites:
- map: votingapp.dev
to: /home/vagrant/laravel/votingapp/public
databases:
- homestead
.env file:
APP_ENV=local
APP_KEY=base64:xxxxxxxx
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=votingapp_development
DB_USERNAME=homestead
DB_PASSWORD=secret
web.php file:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index');
It turns out I had the wrong port number. In the .env file it should be 3306 while in Sequel Pro it should be 33060.
According to the Connecting to databases of the Laravel manual:
You should only use these non-standard ports when connecting to the
databases from your host machine. You will use the default 3306 and
5432 ports in your Laravel database configuration file since Laravel
is running within the virtual machine.
If you use Mamp in 127.0.0.1 add :8889 or the port your config mamp.enter image description here
127.0.0.1:8889 or localhost:8889

Resources