Laravel 4 and PostgreSQL installed on remote server - php

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?

Related

Can't connect to host mongodb from homestead

I have a laravel 5.2 project on homestead 7 which works with mysql and mongodb, I have configured it to connect to host (my mac AMPPS) mysql and mongodb servers.
mysql is connected successfully but I can't connect to host mongodb from homestead.
when I try to connect to host mongodb server from homestead using mongo command I get below error :
vagrant#homestead:~$ mongo 192.168.10.1:27017/admin
MongoDB shell version: 3.2.18
connecting to: 192.168.10.1:27017/admin
2018-01-29T13:18:36.967+0000 W NETWORK [thread1] Failed to connect to 192.168.10.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2018-01-29T13:18:36.968+0000 E QUERY [thread1] Error: couldn't connect to server 192.168.10.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:231:14
#(connect):1:6
exception: connect failed
as you can see my host ip address is 192.168.10.1 and homestead ip address is 192.168.10.10.
And whenever I try to connect to mongodb from laravel mongodb driver I get below error message :
ConnectionTimeoutException in Collection.php line 174:
No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on '192.168.10.1:27017']
FYI : I used This shell script to install mongodb and it's driver on homestead 7 with php 7.1
Any suggestion how to fix this ?
The solution to this problem was to edit host /etc/mongodb.conf and set bind-ip to 0.0.0.0
bind_ip = 0.0.0.0
remember to restart mongodb server, then I connected to the host mongodb server.

Connect to remote database from Laravel Homestead

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

How can I connect to a postgres database using php via an open ssh tunnel?

I need to connect to a postgres database on a remote server using PHP. I've opened an SSH tunnel on the local machine, local port 8000. The tunnel seems to work fine.
The problem arises when I attempt to connect to the db with PHP. The following code:
$ConnectionString = "host=127.0.0.1:8000 user=username password=passphrase dbname=databasename sslmode=require port=5432";
pg_connect($ConnectionString);
produces the following error:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not translate host name "127.0.0.1:8000" to address: Unknown host in [path]\mappage.php on line 22
Not connected
How, then, can I open a database connection via SSH?
For what it's worth, I can connect to the remote PostgreSQL database with PGAdmin using SSH.
As written in the manual it should be:
$ConnectionString = "host=127.0.0.1 port=8000 user=username password=passphrase dbname=databasename sslmode=require";
You had port twice and once incorrectly.
Once you've set up the tunnel, you connect to your database via 127.0.0.1. e.g. (MySQL Example):
ssh -L 127.0.0.1:8000:127.0.0.1:5432 sshuser#example.com
After that the connection parameters for my database are:
Host: 127.0.0.1 (localhost would try to connect to socket)
Port: 8000
User: username
Pass: passphrase

Connecting to MSSQL server using LAMP

I have a LAMP server (Ubuntu 12.04, Apache/2.2.22, MySQL 5.5.24, PHP 5.3.10).
However I also want to connect to other MsSQL server on other machine using Apache & PHP
with a credentials of:
Server name: HENYO-GP-TEST\HENYO_GPTEST
IP: 192.168.1.36
Username: someuser
Password: somepass
Database: somedb
I already installed FreeDTS using 'apt-get install freetds-common freetds-bin unixodbc php5-sybase', then configured it by 'vim /etc/freetds/freetds.conf' then edit the bottom part like this
# A typical Microsoft server
[192.168.1.36]
host = 192.168.1.36
port = 1433
tds version = 8.0
but upon testing using 'tsql -S 192.168.1.36 -U someuser -P somepass -D somedb', the following error occured.
locale is "en_PH.UTF-8"
locale charset is "UTF-8"
using default charset is "UTF-8"
Default database being set to FAC
Error 20009 (severity 9):
Unable to connect: Adaptive Server is unavailable or does not exist
OS error 111, "Connection refused"
There was a problem connecting to the server
But I know the server is on because I can ping it.
Is the connection to MSSQL server (reside on other machine) possible using LAMP?
If it is possible? What are my mistakes on the installation and configuration? Thanks in advance.
Pinging a server doesn't necessarily imply that a particular port is open; it may respond to ICMP requests, but there's no guarantee that a given port is open. Have you confirmed that port 1433 is open on the remote server and that there is nothing blocking traffic to that port?
Your SQL Server is running on an instance named HENYO_GPTEST (HENYO-GP-TEST is the server name, and HENYO_GPTEST is the instance name), but you are not specifying this instance name anywhere.
I'm not familiar with FreeTDS, so I don't know how to specify that, but you need to specify this instance name in order to connect to the server.

Accessing mysql dbase with MysqlWorkBench on VirtualBox (Vagrant - ZF - BoilerPLate)

Does anyone know hot to connect to VB MySQL via MysqlWorkBench. I can log in in virtual box via terminal, but I can not connect it throught MySqlWorkBench. Also I can ping google on vb, ifconfig gave me 10.0.2.15 address, and when I enter it in MysqlWorkBench I got error:
Failed to Connect to MySQL at 127.0.0.1:3306 through SSH tunnel at 10.0.2.15:2222 with user davs
My Virtual box use port 2222 for connecting. Also when I try to connect with ip 127.0.0.1
Failed to Connect to MySQL at 127.0.0.1:3306 through SSH tunnel at 127.0.0.1:2222 with user davs Failed to Connect to MySQL at 127.0.0.1:3306 through SSH tunnel at 127.0.0.1:2222 with user davs
Any advice will be helpfull, thanks.
This looks like an old question but since I just ran into the problem, here are the settings that I used on MysqlWorkbench to get everything working on my mac:
Connection Method: Standard TCP/IP over SSH
SSH Hostname: 127.0.0.1:2222
SSH Key File: /Users//.vagrant.d/insecure_private_key
Mysql Hostname: 127.0.0.1
Mysql Server Port: 3306
Username: root
Password: vagrant
Your settings may be slightly different but the key part is using the insecure private key as was mentioned earlier.
Use the 'insecure private key' located at: ~/.vagrant.d/insecure_private_key

Categories