PHP - Ping another PHP file on a remote server - php

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

Related

How to run the object file in remote computer?

I have a scenario please take a look.
I have two Pcs one is windows and another is ubuntu.
I have installed laravel (PHP) on windows and the necessary files.
On ubuntu, there is only an Object file.
What am i doing is:
on click of a button (from windows) run a function which will connect to ubuntu pc with its credentials,
and run the command to launch that Object file in ubuntu.
How can I achieve this with laravel? any help is appreciated.
all you need is ssh connection
$connection = ssh2_connect('server_address', 'port');
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'your terminal ubuntu command');
see more info here https://www.php.net/manual/en/function.ssh2-exec.php

SSH Tunnel not working Unable to request a channel

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

Connecting to ssh2 in localhost

When I run following code in localhost in Xampp I saw an error that the connection was not success. Now I want know How Can I connect to ssh2 in localhost in Windows in Xampp and what is Username and Password for this connection.' :
ssh2_connect('127.0.0.1','');
For connect to ssh2 in localhost in Windows with Xampp:-
1) Download SSH2 PECL library from PHP.net
2) Extracted the archive's content:-
(2.1)copied/replaced libssh2.dll file to C:\Windows\system32
(2.2)placed php_ssh2.dll and php_ssh2.pdb files in the ext folder (e.g. C:\xampp\php\ext);
3)Remove ';' from the ;extension:php_ssh2.dll line in php.ini. If this line is not on your php.ini, add it.
4) restart the apache server.
Connecting code:-
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, '/usr/local/bin/php -i');
?>
For you i have a perfect solution
Try installing wamp and then going in directory c:/wamp/ .. And then the folder for local host..
Turn try turning on the wamp service u installed above.
VIOLA!

PhpStorm canĀ“t connect to Vagrant to add a remote PHP interpreter (private key not found)

I'm trying to connect to my Vagrant VM to add a remote PHP interpreter. I use the Vagrant option, but when I try to connect I get this error:
I checked if the private_key file exists and it does and it contains a valid private key, any ideas?
Downgrade to Vagrant 1.7.4 resolve this problem
Enter into your vagrant and fix password for user vagrant (example vagrant/vagrant)
create deployement PHPStorm with SFTP type connection
SFTP host = your vagrantFile private network ip
port = 22
Root path = /var/wwww
username = vagrant
auth type = password
password = vagrant
After you can try this connection with click on 'Test SFTP connection'.
If this test run correctly You are sure that your connection SSH into your vagrant is good.
Try the same with Remote PHP interpreter

ssh access to ec2 from php

From local ubuntu linux machine connecting ec2 machine by ssh access.
when i run this php script from terminal it executes fine and write the tailed entries in file. when i run from browser got this error in apache error log
ssh: Could not resolve hostname proxy2: Name or service not known
Found its due to apache user permission problem. whether my guess is right or wrong am not sure. Any one helps me to fix this issue.
php code:-
<?php
$ss = 'ssh proxy2 '.'tail -n 3 /out/speed_log.txt.1'.' > proxy2temp1';
system($ss);
?>
**Finally found an solution using phpseclib and solved my problem. am recommend phpseclib to connect amazon ec2 machines from php uing .pem file to help others share my sample code.
make sure .pem file needs permission to read**
sample code:
include('Net/SSH2.php');
include('Crypt/RSA.php');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('/pathtokey.pem'));
$ssh = new Net_SSH2('ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com');
if (!$ssh->login('user', $key)) {
exit('Login Failed');
}
echo $ssh->exec('tail -n 3 /out/_log.txt.1');

Categories