SSH Tunnel not working Unable to request a channel - php

I'm using PHP 5.6 with ssh2 extension to create SSH tunnel to a remote host, here is my code:
$connection = ssh2_connect("example.com", 22);
if (ssh2_auth_password($connection, "root", "123123")) {
if ($tunnel = ssh2_tunnel($connection, '127.0.0.1', 1080)){
//curl commands
}
}
I can do some Linux commands working with ssh2_exec but can not create SSH tunnel with ssh2_tunnel, here the error logs:
PHP Warning: ssh2_tunnel(): Unable to request a channel from remote
host
Anybody can give me some hints?
Note :
i have AllowTcpForwarding yes GatewayPorts yes inside
/etc/ssh/sshd_config

Related

Build SSH BD connection with local DB connection laravel

In my laravel application there are 2 connection one is for local server and other one is for remote server.
when I run following command to stablish a tunnel connection for remote server, it returns error
Command ssh -i ~/.ssh/dxdy.pem -N -L 3306:[local_server] dxdy#[remote_server]
Error bind [127.0.0.1]:3306: Address already in use
3306 runs MySQL service in local server. So I cant stop it,
What is the solution for this? How to connect to the remote DB with current local DB ?

PHP ldap_bind is not working on azure with a message can't contact Ldap server

I have a laravel 5 app. With the code below, I am able to successfully authenticate with active directory when on localhost and having the company network cabled plugged to my computer.
public static function connect_ldap($username, $password)
{
$ldapServer = DirectorySetting::where('config_key', 'LdapServerAddress')->value('config_value');
$conn = ldap_connect($ldapServer, 389);
if(!$conn) return false;
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
$bindServerLDAP = #ldap_bind($conn, $username, $password);
if(!$bindServerLDAP) return false;
return $conn;
}
How ever, our test and production server is on Microsoft Azure. When I try to authenticate. I get the error below:
Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in /var/www/html/test_ldap.php on line 70
Error Binding to LDAP: No additional information is available
Observation
ldap_connect is successful
I can successfully ping the ldap server address
ldap_bind is unsuccessful. Enabling verbose here doesn't help either. It just tells me that No additional information is available
The system teams says they have created a link between the on premise and azure active dir
My server is CentOS 7, I have enabled the variables httpd_can_network_connect and httpd_can_connect_ldap like below:
sudo setsebool -P httpd_can_network_connect on
sudo setsebool -P httpd_can_connect_ldap on
I have equally added in /etc/openldap/ldap.conf, the variable below:
TLS_REQCERT never
Even with this, it doesn't work.
What could be wrong?

BITCOIN RPC : Failed to connect to localhost port 8332: Connection refused

I can not do a simple easybitcoin command.
Here is my sript :
require_once("../Easy_btc/easybitcoin.php");
$bitcoin = new Bitcoin("pseudo","password");
$result = $bitcoin->getinfo();
var_dump($bitcoin);
I already included the conf file using bitcoind -conf=conf_path
bitcoin.conf :
server = 1
rpcuser=username
rpcpasword = password
By the way,it worked on my ubuntu system but it doesn't on Windows 10

php pdo in linux, not able to connect to remote mysql server but in wamp it's working fine [duplicate]

I am facing a weird problem here
we have a server A where the app files are stored
and B server with database
Tried to connect via command prompt from server A to B using the command
mysql -h xx.xx.xx.xx -u root -p password - and it worked
NOw i tried to create a php script in server A to connect to server B
the command is
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password');
Connection failed: SQLSTATE[HY000] [2003] Can't connect to MySQL
server on 'xx.xx.xx.xx' (13) Fatal error: Uncaught exception
'Exception' with message 'SQLSTATE[HY000] [2003] Can't connect to
MySQL server on 'xx.xx.xx.xx' (13)'
Unable to find a solution on this.
Can any help on this?
thank you
I got it working by running a command in the database server :)
setsebool httpd_can_network_connect_db=1
thanks for the replies yycdev
Try specifying the port in your connection string and ensure the database server is set to allow remote connections and the port is open on your firewall (both of these I suspect are already done as you are able to connect via the terminal but it never hurts to verify and check things).
Change your PDO connection and add the port=3306 or if you're using MAMP use port 8889
$this->db=new PDO('mysql:host=xx.xx.xx.xx;port=3306;dbname=databasename','root','password');
Another thing to check is if – SELinux is blocking network connections. Login as root and run
setsebool -P httpd_can_network_connect=1
I don't know much about that, but try to place the port in back of the script:
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password',3306);

PHP - Ping another PHP file on a remote server

Before I ask the question I will explain the setup.
server 1: vps with CentOS
server 2: vps with CentOS
On server1 I have /var/www/html/test.php
This file must ping get.php on the other server, with some POST variables.
On server2 I have /home/somedir/get.php
So is it possible to ping a file, which is not a webfile?
SSH into server2 via ssh2_exec(). Modified example from php.net:
<?php
$connection = ssh2_connect('server2.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'php /home/somedir/get.php');
?>
Above file should be placed on server1.
Source: http://php.net/manual/en/function.ssh2-exec.php

Categories