Can't connect to host mongodb from homestead - php

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.

Related

MySQL8 connection with php7.3 and Symfony 5 does not work

I have a connection problem with a mysql8 database, php7.3 and Symfony 5. The user and the password are correct !
The connection to MySQL8 database must be done from an SSH tunnel
The SSH tunnel is working :
ssh -p [remote_machine_port] -N -L [mysql_tunnel_port]: 127.0.0.1: 3306 -i / [directory] / private_key [username] # [remote_machine_ip]
MySQL access configuration:
GRANT ALL PRIVILEGES ON 'databasename'.* TO '[user]'#'%' WITH GRANT OPTION;
Doctrine configuration :
DATABASE_URL='mysql://[user]:[password]#127.0.0.1:[port_tunnel_mysql]/[databasename]'
An exception occurred in driver: SQLSTATE [HY000] [1130] Host '127.0.0.1' is not allowed to connect to this MySQL server
I have the same problem with heidiSQL and on the VM
I tried with the Ip of the VM instead of 127.0.0.1
ssh -p [port_machine_distant] -N -L [port_tunnel_mysql]:[ip_machine_vm]:3306 -i /[directory]/private_key [username]#[ip_machine_distant]
Doctrine configuration
DATABASE_URL='mysql://[user]:[password]#[ip_machine_vm]:[port_tunnel_mysql]/[databasename]'
An exception occurred in driver: SQLSTATE [HY000] [2002] Connection refused
However, this setting works with heidiSQL but not with the Symfony application !
Did I forget a setting on the VM or Mysql ?
127.0.0.1 connection issue :
We have created the '[user]'#'127.0.0.1' rights.
In MySQL, 127.0.0.1 uses the network and localhost uses the socket.
The message "The server requested authentication method unknown to the client [caching_sha2_password]" was caused because the setting 'default-authentication-plugin=mysql_native_password' was created after the creation of the rights.
We regenerated the rights, and now everything is working fine.

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

Phpmyadmin corrupted

I'm trying to recover the root password for phpmyadmin. I followed some tricks found on the net, and now I have a deeper problem.
I can't login to phpmyadmin. I'm getting the following error:
\#2002 - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
The server is not responding (or the local server's socket is not correctly configured).
Connection for controluser as defined in your configuration failed.
I ran the following command to verify if my MySQL is running,
mysqladmin: connect to server at 'localhost'
And I'm getting the following message:
failed error: 'Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)' Check that mysqld is running and
that the socket: '/var/run/mysqld/mysqld.sock' exists!
I'm not sure what to do next.

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?

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.

Categories