Can't connect to MongoDB on remote host via php - php

I have such network configuration (see link - http://s58.radikal.ru/i160/1110/4c/1c2c5d74edd0.jpg)
Where:
Notebook - contain Apache+php+mongodb+php drivers for mongodb+web project on Zend (Windows)
router - virtual station (nat on 192.168.5.23 interface + ipfw)
natd.conf:
interface le0
same_ports
use_sockets
redirect_port tcp 192.168.5.23:27017 27017
redirect_port tcp 192.168.5.23:27017 27017
ipfw:
allow from any to any
virtual station 2 - contain ONLY mongodb (no php, apache, or mongodb php drivers )
1 - ping from notebook to mongodb host and backward - works.
2 - shell on virtual mongodb host: mongo 192.168.5.20:27017 - connected to notebook's mongodb successfully
3 - attempt to connect from notebook to virtual host cause such error:
C:\mongodb1.8.2\bin>mongo 192.168.9.21:27017
MongoDB shell version: 1.8.2
connecting to: 192.168.9.21:27017/test
Sun Oct 02 22:31:14 Error: couldn't connect to server 192.168.9.21:27017 shell/mongo.js:81
exception: connect failed
4 - attempt to use remote host with DB in php project (www.vm.lcl):
an exception occured while bootstrapping
connecting to vm-db1.lcl failed: Unknown error
Stack Trace:
#0 C:\www\vm-db1.lcl\library\Zirrk\Database\MongoConnection.php(16): Mongo->__construct('vm-db1.lcl')
Please, give me advise - in what direction should I search my mistakes!
Thank a lot!

I've solve this problem by changing rule in natd.conf
redirect_port tcp 192.168.5.23:27017 27017
to
redirect_port tcp 192.168.5.23:27017 192.168.9.21:27017
Before understanding how to fix it, I've create in virtual network (192.168.9.0/24) web-server (192.168.9.11) with apache+php+mongo-php-driver (mongodb - was not installed), and tried to connect to 192.168.9.21
$m = new Mongo("mongodb://192.168.9.21:27017");
This was no sense. I've spent whole day in brainstorm and googling information, but still nothing. (Error was in timeout while connection to server). Then I rest for few hours, and understand, that in my case, all traffic goes through Freebsd-gateway host and add to natd.conf
redirect_port tcp 192.168.9.11:27017 192.168.9.21:27017
reboot gate-way server, and it come to work!

Related

REDHAT 8 Apache PHP SAPNWRFC gkralik / php7-sapnwrfc only works from CLI - SAP

I'm using this repo to connect to SAP software:
https://github.com/gkralik/php7-sapnwrfc
but I don't know why my script connect and return data successfully from my zfunctions on SAP server only under Command Line Interface CLI
php /path/tomy/script.php
but errors under web browser always return:
Fatal error: Uncaught SAPNWRFC\ConnectionException: Failed to set trace directory in /var/www/html/sap/test.php
or
Exception: Could not open connection
Exception INFO:
Array
(
[code] => 1
[key] => RFC_COMMUNICATION_FAILURE
[message] =>
LOCATION CPIC (TCP/IP) on local host with Unicode
ERROR partner 123.4.5.6:3300 not reached
TIME Sat Feb 4 23:42:27 2023
RELEASE 753
COMPONENT NI (network interface)
VERSION 40
RC -10
MODULE /bas/753_REL/src/base/ni/nixxi.cpp
LINE 3067
DETAIL NiPConnect: 123.4.5.6:3300
SYSTEM CALL connect
ERRNO 13
ERRNO TEXT Permission denied
COUNTER 6
)
with any user, and I have checked file permissions too.
Thank you very much for your help
By default, SELinux forbids Apache to make outgoing network connections. If Apache needs to make requests to an outside network service, then run the following command to allow this action.
setsebool -P httpd_can_network_connect on

PDO exception while sending request from inside a container

First situation:
I run the php artisan migrate command from a terminal on a laravel project, and it works fine updating the mysql database on
127.0.0.1:3306. This means that the php-mysql connection was fine.
Second situation:
Running the project inside a docker container I was not able to set
the database to 127.0.0.1 since in a docker container that matches
the container itself. I read that docker has a bridge to connect
with the host (in the case of Linux 172.17.0.1). So I changed the mysql
connection settings to 172.17.0.1:3306. And I get:
PDOException
Packets out of order. Expected 0 received 1. Packet size=69
and
PDOException SQLSTATE[HY000] [2006] MySQL server has gone away.
Question:
Why does it work with 127.0.0.1 but from not from inside a container?

Connection error to mssql from Centos7

I have Centos7 installation with nginx/php5.6. MS SQL 2008 R2 is working on another server.
MSSQL definitely has allowed tcp connection, custom (non domain) user, firewall disabled, and I can connect to it using HeidiSQL and that setting from another Windows machine.
I can telnet to MSSQL from Centos (and I see Log error "Length specified in network packet payload did not match number of bytes read; the connection has been closed. Please contact the vendor of the client library." with centos ip address in MSSQL logs, so no errors here).
I couldn't connect to mssql from centos using php_mssql or sqlcmd;
During sqlcmd:
Microsoft (R) SQL Server Command Line Tool
Version 13.1.0007.0 Linux
[root#***]# /opt/mssql-tools/bin/sqlcmd -S *** -U ***
Password:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Timeout error [258]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Unable to complete login process due to delay in prelogin response.
During php interactive:
php > mssql_connect('***:***', '***','***');
PHP Warning: mssql_connect(): Unable to connect to server: *** in php shell code on line 1
I also tried tsql/freetds:
/etc/freetds.conf has section
[myserver]
host = ***
port = ***
client charset = UTF-8
tds version = 8.0 //also tried 7
[root#*]# tsql -S myserver -U ***
Password:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
5 //begins to count, i could't understand what does it mean
Also tried to clean it all and install php7.0 with sqlsrv extension - the same problem;
There are some network strange - Centos serv and MSSQL are in different networks, I couldnt ping mssql from that server, but can telnet, i'm using ip, not the host name during connection attempts, so don't think it's a big deal.
Now I am out of ideas where to dig, any suggestions, please?
It was caused by misconfiguration in the network, I don't understand exactly how it is possible - to make telnet connection, but fail to connect normally, but our IT guys repaired this problem in less then half an hour.

Nginx and Aegir installation on Ubuntu fails

I am installing Aegir with Nginx on vanilla Ubuntu 14.04 VPS following:
http://community.aegirproject.org/content/installing/manual/nginx-mariadb-php-fpm-single-server-installation
At the very end, during Aegir install I get following error:
Could not rsync from '/var/aegir/config/server_master/nginx/subdir.d' to 'aegir# nginx.drophost.eu:/' [error]
/var/aegir/config/server_master/nginx/subdir.d could not be synced to remote server nginx.drophost.eu. Changes might not be available[error]
until this has been done. (error: ssh: Could not resolve hostname nginx.drophost.eu: Name or service not known
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0])
Server domain is nginx.drophost.eu and it resolves correctly to server IP, so what's wrong?

Fatal error: Uncaught exception 'RedisException' with message 'Redis server went away'

One of my application suddenly started to give error:
Fatal error: Uncaught exception 'RedisException' with message 'Redis server went away' in /var/www/_slim/_core/system/generator.001.php:133 Stack trace: #0 /var/www/_slim/_core/system/generator.001.php(133): Redis->auth('77B1BFFBC0378DF...') #1 /var/www/_slim/_core/system/generator.007.php(144): Generator001->r6_redis_start('R') #2 /var/www/_slim/_core/system/generator.007.php(26): Generator007->HarvestRedis() #3 /var/www/_slim/_core/system/generator.shopping.php(14): Generator007->Generator007() #4 /var/www/_slim/_core/system/generator.last.php(43): Generator008->Generator008() #5 /var/www/_slim/site/home/php/index.php(16): GeneratorLast->GeneratorLast() #6 /var/www/index.php(96): Gui->Gui()
#7 {main} thrown in /var/www/_slim/_core/system/generator.001.php on line 133
I have reinstalled redis-server but no luck so far. Any suggestions?
Maybe not the answer to the specific question, but might help those new to Redis who come here by googling the Exception.
You will also get this exception if you create a Redis instance and start to call methods on it without first connecting to a Redis server by calling
$redis->connect('localhost')
The arguments for the call should obviously be adjusted if Redis is not a local host, configured to listen on a different port, set up a password etc.
Well, as the exception describes itself, your Redis server is down.
Try the following stuff:
See if the server that runs the Redis instance contains any firewall on (iptables, maybe?).
Go to your web server (that runs your php) and try to telnet to your redis server.
See if the configured host/ip is correct. Maybe something in the network settings of the Redis server have been changed.
I had a problem connecting to the redis
I managed to solve it by changing the colon to a comma
$redis->connect('localhost:6379');
from this to this
$redis->connect('localhost', 6379);
If you are running on a local/dev environment, make sure that Redis Service is running.
You can check if your local service is running by opening the Redis Client cmd. If you are on a MAC open the command line and type redis-cli.
If your server is running you should see:
redis 127.0.0.1:6379>
In my case I forgot to start the windows service so all I had to do was to: open services.msc, start Redis Server service.
I've had the same issue when integrating my software with local Redis installation. Turned out "localhost" host name was not resolved (stuff was was running in a docker container which didn't know that). Changed it to regular loopback IP "127.0.0.1" in the client config and it rolls.
My issue was that I was using Docker Compose and needed to use the name of the container instead of 'localhost'.
// Connect to the Redis Docker created server. 'redis' refers to the
// 'redis' container in the docker-compose.yml file.
$redis->connect('redis');
// docker-compose.yml
redis:
image: redis:alpine
volumes:
- redis-data:/data
ports:
- ${FORWARD_REDIS_PORT:-6379}:6379
healthcheck:
test: ["CMD", "redis-cli", "ping"]
networks:
- default

Categories