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
Related
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!
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
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
I have installed FreeTDS 0.91, ODBC, on a Cpanel server running Centos 6.5x64. Everything appears to be running fine and I can connect to the remote MSSQL 2012 server using:
/usr/local/freetds/bin/tsql -S sqlserver -U test -P mypassword
and succesfully execute queries in the database.
I can also connect through:
isql -v sqlserverdatasource test mypasswordhere
But for some reason /usr/local/freetds/bin/tsql -LH server.ip.here
returns no information or errors which doesn't make much sense when it is proven I can connect with the other methods above.
So now when running a test script from a cpanel account on the machine I get:
Unknown host machine name (severity 2)
Here is the test script:
//Database connection function.
function getConnection() {
try {
//$dbconnect = new PDO("sqlserver:Server=server.ip.here,1433;Database=dbname", "user", "password");
$dbconnect = new PDO("dblib:host=server.ip.here,1433;dbname=dbname", 'user', 'password');
} catch (PDOException $e) {
echo "CONNECTION ERROR.<br>Error message:<br><br>" . $e->getMessage();
die();
}
if (!$dbconnect) {
die('Cant connect to database. Please try again later!');
}
else{
echo "i'm in!";
return $dbconnect;
}
}
The first commented line is the old one using sqlserv which I found did not work at all from what i can tell because of the x64 OS. I have also tried with "" around user and pass as well as no marks at all.
php -m does show PDO and pdo-dblib.
Any ideas where I can look next?
Update: This was fixed. I missed in freetds.conf:
[global]
# TDS protocol version
tds version = 8.0
It was originally set to 4.5 instead of 8.
The fix for me was with three steps:
First, I edited /etc/freetds/freetds.conf and changed the tds version like this:
tds version = 8.0
The second step was not entering port number. The port was already 1433, and not specifying it fixed the exact same issue on my case.
Lastly, to connect properly, I had to restart networking as #user1054844 mentioned as this:
/etc/init.d/networking restart
After all these steps, I was able to connect and work with the SQL Server database.
You actually did not need ODBC at all since your connect script is using pdo_dblib not odbc. You can just install FreeTDS than enable pdo_dblib via the compile time flag in rawopts and rebuild via EasyApache. Of course cPanel specifics for this are a bit different.
I just did this for a friend and decided to document it since it is hard to find accurate clear information for FreeTds and pdo_dblib on cPanel.
Guide is here: FreeTDS And pDO_dblib On cPanel
I'm trying to get a PHP 5.3.10 installation on Ubuntu 12.04 to connect to a a remote SQL Anywhere 12 (Sybase?) server using ODBC (unixODBC). However, PHP's execution halts at odbc_connect().
PHP code:
$odbc = odbc_connect('DSN=TP189902;', 'username', 'password');
if ($odbc)
{
echo 'Connected';
}
else
{
echo 'Failed: '.odbc_error($odbc);
}
So regardless of whether or not it connects, it should be outputting one of the echos, but it doesn't. If I try using PHP's PDO library instead, I get the same result.
My unixODBC setup looks like the following. And this might be where my mistake is, because I've never setup ODBC on linux before and am not very familiar with it.
odbcinst.ini
[SQL Anywhere 12]
Description = SQL Anywhere 12
Driver = /opt/sqlanywhere12/lib64/libdbodbc12.so
Setup = /opt/sqlanywhere12/lib64/libdbodbc12.so
odbc.ini
[TP189902]
Description = TP189902
Uid = username
Pwd = password
Driver = SQL Anywhere 12
ServerName = 189902
CommLinks = tcpip(Host=1.2.3.4)
DatabaseName = DB189902
I've also tried a ton of alternatives, such as using the driver's path for the Driver value, using Host=1.2.3.4 instead of CommLinks, etc.
Also the command isql -v TP189902 username password doesn't output anything unless I give it a fake DSN so that it outputs and error.
I've also verified that libdbodbc12.so is the same architecture as isql and that it has all of it's dependencies.
On top of this, I have very similar setup on a Windows 7 machine running WAMP, that connects just fine (with both the ODBC and PDO library). I used the same DSN details on it.
Edit: I've also tried this to skip the DSN, but it gives the same result. It also works on the Windows box.
$odbc = odbc_connect('Driver={SQL Anywhere 12};Server=189902;CommLinks=tcpip(Host=1.2.3.4);', 'username', 'password');
I don't use PHP these days but here are some things I've spotted:
I would totally ignore php until you get isql working.
I'm assuming it is a typo that you say your system ini file is "odbcinstr.ini" - it should be "odbcinst.ini".
How do you know you are looking at the right odbc ini files - run odbcinst -j to check the locations unixODBC is using.
I know where that "[ODBC Data Sources]" section comes from (iodbc) but it not at all necessary for unixODBC - just delete the first 2 lines of your odbc.ini file.
your isql line is probably missing a username and password - it should be "isql -v TP189902 username password". I cannot for the life of me see why it would output nothing at all.
Ultimately the issue was getting the LD_LIBRARY_PATH set to /opt/sqlanywhere12/lib64 for Apache.
Setting it in /etc/environment got isql -v TP189902 and php connect.php working when called from any shell user, but not Apache.
To get Apache to see it, I had to edit /etc/init.d/apache2 and change
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
to
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sqlanywhere12/lib64".
And then restart the Apache service.
Various other methods I found online to do this did not work.
One caveat is that with the path set, unixODBC still won't read my system DSN file for some reason. So to get Apache to access the DSN, I had to make a user DSN file (.odbc.ini) in /var/www, as that's the Apache user's (www-data) home folder.