How to use postgreSQL in Laravel Homestead - php

I can do migration to my homestead.
this is my .env
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=54320
DB_DATABASE=intern
DB_USERNAME=homestead
DB_PASSWORD=secret
And I make a new server in my postgreSQL with
server name = Homestead,
username = homestead,
password = secret.
then, I did migration and all the table created into my database(server=homestead)
The problem is, when I want to do login in my site. It occurs an error:
SQLSTATE[08006] [7] could not connect to server: Connection refused↵
Is the server running on host "localhost" (::1) and accepting↵
TCP/IP connections on port 54320?↵could not connect to server: Connection refused↵
Is the server running on host "localhost" (127.0.0.1) and accepting↵
TCP/IP connections on port 54320? (SQL: select * from "users" where "email" = user#gmail.com limit

You have an extra 0 at the end of your port. Change DB_PORT=54320 to DB_PORT=5432

try to access your homestead with ssh.
i think u already change the password from the inside
from laravel documentation i think that config should work
or try this command after u change the config
php artisan config:cache and php artisan cache:clear
https://laravel.com/docs/5.6/homestead#connecting-to-databases

Related

How to access PostgreSQL server from Laradock?

I've attempted to access my PostgreSQL database from both a Laravel project, DBeaver and Artisan. Accessing it from Laravel project or Artisan ($ php artisan migrate) always results in:
Illuminate\Database\QueryException
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 5432?
Because I'm not relying in my Laradock settings and I'm not familiar with Laravel in general, I did re-download Laradock with default settings, but situation continues same.
Partial laravelProject/.env:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret
Partial laradock/.env:
POSTGRES_VERSION=alpine
POSTGRES_DB=default
POSTGRES_USER=default
POSTGRES_PASSWORD=secret
POSTGRES_PORT=5432
Environment used to run Artisan:
$ docker-compose exec --user=laradock workspace bash
I installed Laravel in this environment using composer global require laravel/installer.
DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=yourprojectdatabase
DB_USERNAME=default
DB_PASSWORD=secret
To connect using DBeaver:
Host: localhost
Port: 5432
Database: you can leave it empty
Username: default
Password: secret
Click on the PostgreSQL tab right there in Connection.
Make sure "Show all databases" is checked.

Bd Postgres connection to Laravel?

I had a problem that I could not solve a few days ago, I try to connect with my Postgres bd which is on a server, I work with laravel but it has highlighted an error when I connect to my Postgres bd, this error appears
PDOException in Connector.php line 55:
SQLSTATE[08006] [7] could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
error image:
I would like to know if it has happened the same and how to solve it, Thanks!
Change in your .env setup like this:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1 //If you want to use only in localhost or otherwise change according to host server
DB_PORT=5432
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password
After changes of .env edit please enter this command in your terminal for clear cache:php artisan config:cache
Changing the DB_HOST to postgres, helped me to solve mine.
DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=your-database-name
DB_USERNAME=user-name
DB_PASSWORD=your-password
Hard to tell without your environment file. This error might occur because you are already connecting to postgres,
To check, make sure this line is in your .env file:
DB_PORT=5432
Or, you can remove the line from the .env and let Laravel choose the default according to the connection:
'port' => env('DB_PORT', '5432'),
Another cause for failed connection due to auth is that the env file is looking for 127.0.0.1. Sometimes changing this to localhost will help.

Laravel Nova + Homestead SQLSTATE[HY000] [2002] Connection refused

I have a fresh installation of Homestead 7.17.0, Laravel 5.7.2 and Laravel Nova 1.0.14 but when I try to login with a username and password I added to the user's table, I get the following error:
Illuminate\Database\QueryException SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `email` = user#email.com limit 1)
I'm sure the database configuration in my .env file is correct. Actually, I added the user via a and artisan command I've created and which prove the main app can connect to the database without problems.
Double check your port, when I used Homestead on my Mac the port was 3306 for running artisan commands but for loading the web application in a browser it needed to be 33060

Laravel Homestead connect to remote database SSH

I'm stuck how to connect to remote database.
I've already tried to run
ssh -fNg -L 3307:127.0.0.1:3306 forge#128.xxx.xxx.xxx
and my .env
DB_CONNECTION=mysql
DB_HOST=128.xxx.xxx.xxx
DB_PORT=3307
DB_DATABASE=projectdb
DB_USERNAME=forge
DB_PASSWORD=password;
I can connect the remote database using HeidiSql. But when I tried to connect using laravel project it always return me
SQLSTATE[HY000] [2002] Connection timed out
Any other solution?
In that scenario, your .env file should have setting DB_HOST=127.0.0.1 since you're tunneling (local) traffic from your Homestead server on port 3307 to traffic into the remote server on port 3306, specifically also on 127.0.0.1.
Another way to write that more explicitly would be:
ssh -fNg -L 127.0.0.1:3307:127.0.0.1:3306 forge#128.xxx.xxx.xxx
(However, you can keep your current command of ssh -fNg -L 3307:127.0.0.1:3306 forge#128.xxx.xxx.xxx, I'm just showing you how you can write that another way to hopefully make the point more clear).
So, from Homestead, if you send traffic to 127.0.0.1:3307,it will get tunneled into the remote server and then connect to 127.0.0.1:3306 within it.

Laravel SQLSTATE[HY000] [2002] Connection refused

so I want to deploy my existing Laravel project into my digital ocean VPS
I used this tutorial and I uploaded my site successfully.
My .env file is:
APP_ENV=local
APP_KEY=my app key
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=my ip
DB_PORT=3306
DB_DATABASE=form
DB_USERNAME=root
DB_PASSWORD=my pass
But here is the problem: I used MySQL and created and ran
php artisan migrate
and got these errors:
[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = form and table_name = migrations)
and
[PDOException] SQLSTATE[HY000] [2002] Connection refused
In your .env file, change DB_HOST from 127.0.0.1 to localhost
Put string:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
after DB_PASSWORD=
It works for MAMP. Set your path to mysql.sock
In your .env file, change DB_HOST from 127.0.0.1 to localhost
and then
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
This worked for me.
There are a few possibilities why your getting this error.
database server isn't started, check if you can still use your phpmyadmin. If you can still use it then nothing is wrong with your database server.
wrong config; check username, password and server settings in both your .env file and your config/database.php
no privileges to the server and or database with given credentials
Looking at the steps you already took I think it's the last.
Check to see if this user has access to the database from the remote location. By default the root user has access to the server locally (localhost,127.0.0.1 and ::1).
So check to see if the user has access from either your remote ip or from anywhere.
As you are using digitalocean I would suggest to check if they have a specific configuration to connect to mysql database.
SELinux might be the cause.
Set this rule and try again:
sudo setsebool -P httpd_can_network_connect_db=1
After long hours this worked for me:
Changing the port in php My Admin previously 8889
APP_NAME=laravel
APP_ENV=local
APP_KEY= YOUR KEY
APP_DEBUG=true
APP_URL=127.0.0.1
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
and then
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
Before you do changes as per instructed above,
check if your database server running or not. If you are using command prompt, running mysql.server status or mysqld status shall show the database status.
If the database is running, check if the dbuser is allow to connect from '%' or 'localhost' or '127.0.0.1'. If not, just grant the user access from '%'
If you have done 1 and 2 and still can't connect, see if the db user is allow to access the schema. If not, grant access to the schema
If you reach here and still got the same error, try to restart you web server.
My composer was installed globally, i run php artisan serve without starting xampp & getting this error. After running my xampp server, it's working fine from my side.
In attempt to provide a solution for those of you that have not found success in any of the already mentioned answers, I will share my solution.
Coming from Windows 10 I was of the understanding that the password for the root user was always blank thus my .env file looked as follows:
DB_USERNAME=root
DB_PASSWORD=
On Mac, the password is defaulted to "root" also. Changing my .env file to look as follows fixed my issue:
DB_USERNAME=root
DB_PASSWORD=root
in your .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ur_db_name
DB_USERNAME=ur_db_username
DB_PASSWORD=ur_dbuser_password
If you are using XAMPP on Mac, just use the embedded IP Address from your XAMPP Dashboard as DB_HOST instead of 127.0.0.1 or localhost.
If It still refuses to connect deal with a user but stick on that idea.

Categories