Connect to remote database from Laravel Homestead - php

I am trying to connect my Homestead Laravel project to a remote db hosted on Fasthosts but I get the error ;
ssh: connect to host 213.xxx.xxx.xx port 22: Connection timed out
I have tried this in my homestead
ssh -fNg -L 3333:localhost:3306 user#213.xxx.xxx.xx
This is my .env db settings
DB_CONNECTION=mysql
DB_HOST=213.xxx.xxx.xx
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=user
DB_PASSWORD=xxxxxxx
I am not sure why the connection to the remote database is timing out. Any ideas to help is muchly appreciated.

if your databse stack is bitnami there is a process to open port, and if your stack is on AWS and is bitnami stack you must open ports in the cloud platform of amazon

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.

How to use postgreSQL in Laravel Homestead

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

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 4 and PostgreSQL installed on remote server

I've installed Laravel 4 on a windows machine with XAMPP and PostgreSQL on a virtual machine (Ubuntu).
I also edited below files on PostgreSQL machine (ubuntu) to work correctly:
/etc/postgresql/9.1/main/pg_hba.conf
/etc/postgresql/9.1/main/postgresql.conf
In a raw php: on my Windows machine I can connect to PostgreSQL database on the remote machine by the below code and everything is okay:
$dbconn = pg_connect("host=192.168.56.101 port=5432 dbname=gis user=gisuser password=mypass");
$sql="CREATE TABLE users (id varchar(5),name varchar(20),PRIMARY KEY(id))";
pg_exec($dbconn, $sql) or die(pg_errormessage());
now users table was created in my PostgreSQL database.
But in Laravel: I can't connect with the same config. I setup everything in database.php and when I run the following artisan command:
php artisan migrate:install
the following error occured in command line:
[PDOException]
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?
migrate:install [--database[="..."]]
Can anyone please help me to connect to my remote PostgreSQL server via Laravel 4 on my Windows machine?

Categories