Connecting to ssh2 in localhost - php

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!

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

PHP not able to connect to MySQL in Ubuntu based custom S2I image

Playing with Openshift origin 3.9 on my custom servers. So far it has been a pleasant experience. I've been building a custom s2i image based on Ubuntu for my LEMP stack.
I'm not able to connect to the MySQL database. I always get an error saying:
Failed to connect to MySQL: (2002) No such file or directory
Here's my PHP code:
$mysql_database = getenv("MYSQL_DATABASE");
$mysql_server_name =getenv("MYSQL_HOST");
$mysql_username = getenv("MYSQL_USER");
$mysql_password = getenv("MYSQL_PASSWORD");
$mysql_port = getenv("MYSQL_PORT");
$mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database, $mysql_port);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
die();
}
Some observations:
I'm able to connect from MySQL CLI client from inside the pod.
The same app/code works fine with the official openshift PHP s2i image.
Am I missing anything in my s2i?
Check your phpinfo() and search for MySQLi extension. If you can't find, that means you do not have the extension installed yet and it needs to install.
try installing from terminal
(Ubuntu/Mint) $ sudo apt-get install php(version)-mysql
replace (version) with any of your php version number. For example, php7.0 / php7.1, etc.
To check phpinfo(), create a phpinfo.php file which you can access from url with the content
<?php
phpinfo()
If you have everything and still unable to connect? Try checking your mysql.sock file path.
Open the php.ini file and find this line:
mysql.default_socket
And make it (know where your mysql.sock located)
mysql.default_socket = /path/to/mysql.sock

mysql_connect(): No such file or directory in /opt/lampp/htdocs/

I have installed XAMPP on my Ubuntu 14.0.04 and I'm trying to connect to my MySQL server from PHP file but I'm getting an error:
Warning: mysql_connect(): No such file or directory in /opt/lampp/htdocs/value.php on
line 3
not connected
my value.php file contains
<?php
$con = mysql_connect('localhost:3307', 'root', '');
if ($con) echo 'Connected';
else echo 'not connected';
---
?>
and my MySQL server is up and running and my server is also running.
Which version of mysql are you using?
Try this
127.0.0.1:your-port-number
like
$con = mysql_connect('127.0.0.1:3307', 'root', ''); // or 3306 whatever your port number is
instead of localhost
I too had this problem, but this link helped me Warning: mysql_connect()
It looks like mysql has got the location of the socket file wrong; and it can be fixed by simply setting the symbolic link to correct it.
The socket file (zero length file) will be either be available in /tmp/mysql.sock or /var/mysql/mysql.sock. Depending on which one is missing create a symbolic link for other.
cd /var
sudo mkdir mysql
sudo chmod 755 mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock

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

Can not connect to SQL SERVER Using Latest Drivers for PHP

I have been trying to figure out which dll and how to use it to connect to sql server.
It was much easier using the old php_mssql.
I am using Xampp on WinXP Pro SP3. I have been unable to figure out how to connect, i have search the manual, and none of the command's work.
I get PDO Error Driver Not Found
extension-php_pdo_sqlsrv_54_ts.dll
extension=php_sqlsrv_54_ts.dll
I realized that I must use the SQLSERV 2.0 Drivers. But which dll is the correct one? And what syntax must I use to connect and run queries?
Thank you.
One way of doing this is using FreeTDS for Windows
I am assuming you have PHP >5.3
Download this http://download.moodle.org/download.php/dblib/php53/DBLIB_TS.zip
Add this line to your php.ini extension=php_dblib.dll
You will also need to make a file called freetds.conf in the root directory of your PHP installation.
It should look something like this:
[global]
host = xxx.xxx.xxx.xxx (host name or ip of the MSSQL server)
port = 1433
client charset = UTF-8
tds version = 8.0
text size = 20971520
Restart Apache and try running this script:
<?php
$link = mssql_connect('localhost', 'db_user', 'db_password');
if(!$link) {
echo'Could not connect';
die('Could not connect: ' . mssql_error());
}
echo'Successful connection';
mssql_close($link);
?>
hit me up on fb if this does not work ;)

Categories