php artisan migrate throws received invalid response to SSL negotiation - laravel

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.

Related

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

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

Can I connect Laravel on Heroku with Awardspace database?

I added in ENV file on Heroku informations from Awardspace, because I want to connect that database with Laravel project deployed on Heroku.
I am getting error SQLSTATE[HY000] [2002] Connection refused
you have these credentials you should put it in settings -> config vars->
DATABASE_URL
DB_CONNECTION=pgsql
DB_DATABASE
DB_HOST
DB_PASSWORD
DB_PORT
DB_USERNAME
after added these credentials with database
you should run in bash php artisan migrate
and work fine
hopefully that is help you
use this command for clear cache.
php artisan optimize:clear
php artisan optimize

Connection could not be established with host mailhog :stream_socket_client()

I'm getting an error in mailhog while sending an email to new user for creating password.
Error:
Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known.
.env config:
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="dev#example.com"
MAIL_FROM_NAME="${APP_NAME}"
Do you use sail package for laravel? If you are using laravel sail you should set:
MAIL_HOST=mailhog
Otherwise it must be:
MAIL_HOST=localhost
Also enter a value for MAIL_FROM_ADDRESS:
MAIL_FROM_ADDRESS=a#gmail.com
In recent versions of Laravel Homestead, if you take a look at the Homestead.yml file, almost at the top you can get the IP address set for the Homestead Virtual Machine.
Copy that address to your .env file and set it instead of mailhog:
MAIL_HOST=192.168.56.56 #mailhog
Then you can access Mailhog with your browser by typing
http://192.168.56.56:8025/
This problem occurs when some changes have been made to files, specifically in .env file. I was facing the same issue and solved by this solution.
Clear cache using artisan command
php artisan cache:clear
Clear config
php artisan config:clear
Restart your server
sudo service apache2 restart
More: Try clearing browsers cache & cookies.

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 not connecting to homestead database

I was developing a laravel application locally on Mac connecting to a mysql database. i recently found out about homestead and pulled my app over to Vagrant Homestead. however now im not able to connect to the mysql server on the homestead/box.
Error i recieve:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
I did update my app's .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=eHDatabase
DB_USERNAME=homestead
DB_PASSWORD=secret
I cleared my app's cache
php artisan cache:clear
I updated my /etc/hosts file
27.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 laravel.app
and i also removed the old mysql server running on port 3306 on 127.0.0.1.
but still recieve the connection error.
Any help would be great.
Both .env and /config/database.php are looking fine, so try to run this:
php artisan config:cache

Resources