How to connect remote Linux box through PHP in windows environment - php

I'm on a Windows XP machine, with Wamp installed. Currently, I am using putty to connect my remote Linux boxes.
I want to execute Linux commands through php shell_exec() method (cp, ls, ...).
Does anybody know how to connect my Linux box first and then run those commands in a Windows environment?
Any advice's would be highly appreciated...

You can't run Linux commands in Windows.
You can run them over SSH, using putty. It seems you have that running.
You can forward the connection over ssh. Look in the putty screen, go to Connection > SSH > Tunnels.
Then you add a tunnel:
source port: 1234
destination port: localhost:80
type is Local
So you open Internet Explorer, type in the addres bar: http://localhost:1234 the port 1234 is then forwarded to the port 80 on the remote linux pc.
You can also forward it to the WAMP by setting
destination port: *ip of the wamp server*:80
Then you can acces the Windows pc from outside the network, as long as putty is running.

It sounds like you want a PHP script on Windows to run SSH commands on a remote Linux server. For this, see the PHP SSH2 extension.
Bindings to the libssh2 library which provide access to resources
(shell, remote exec, tunneling, file transfer) on a remote machine
using a secure cryptographic transport.
This will allow you to connect to the Linux server via SSH and execute commands on the remove server (cp, ls, etc.). Here's some sample code:
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'hostname');
echo "Output: " . stream_get_contents($stream);
It's worth noting that this probably isn't the safest or most reliable way to go about this task.

I don't think you can execute linux commands on a windows machine.
You might want to consider using OpenSSH for Windows
and skip the php.
But you will get you a Windows Shell. C:\\> and no ls or cp, but otherwise full control.
You could also get experimental and run a Virtual machine with linux and share your windows drive with it.
remote server linux - - ssh - - > local virtual linux - - - shared folder - - > windows

You could either:
Install CYGWIN
Install SSH2 extension for PHP
There is an extended SSH2 class I use, which can be found here: SSH2 with Exception Handling.

Related

Execute export command in windows

Hello I am trying to execute this command:
export PATH="$HOME/.composer/vendor/bin:$PATH"
in windows.
Please, check these notes
Note: For the local PHP environment I am using a Mac and Valet because it automatically sets up everything. If you are on Windows, you should consider Homestead or some flavor of a virtual machine.

SSH to wamp server apache / php from Linux Sub-System

I am trying to ssh to my Wamp Server 3.0.6 installation on Windows 10 from Linux SubSystem but it is asking me for a password. Trying to do a mysqldump of all databases but I don't have anymore an apache console so need to use this one. What password would this contain. I tried blank password, my own linux subsystem password but it's not that one.
Linux subsystem
You will not be able to SSH to the WAMP installation. SSH is something available from within the OS (not normally in Windows but in Linux). So on your Linux machine you have a SSH server installed and this allows you to connect to it via SSH.
What you want to do, is use the MySQL client on the Linux machine to access the MySQL server that is running on the Windows Machine.
For this you firstly need to ensure that the Windows machine has port 3306 open in the firewall and that the MySQL server has a user like 'user'#'%' or 'user'#'linux.machine.ip'.
Then on the Linux machine you can do:
mysqldump -u user -p -h windows.machine.ip database > backup.sql
That being said, it's likely going to be easier for you to run this command on the Windows machine:
mysqldump -u root -p database > backup.sql
I have not used WAMP in years but the MySQL client software is in something like wamp/bin/mysql, look for mysqldump.exe and from this folder can run the above command in command prompt.
As you'd not need to configure remote access to the MySQL server from within Windows. You can then just SFTP into the Linux box and upload the file or SCP to copy the file from Windows to Linux.
Regarding the default password for your MySQL install, it should be root with no password but bear in mind that the MySQL server needs a user account with remote access.
Also, if you're running that Linux box in a VM on the Windows box, check out Samba shares as you could share the Linux file system with the Windows machine, would make it easy to copy things back and fourth.

Setting php environment variable on windows with vagrant

i'm trying to run "php artisan" comands on Windows, but the system returns an error that php variable path isn't set.
The problem is that i don't have php installed directly on the Windows system, but it is installed on the vagrant box.
Any ideas how to set the windows php environment variable to the vagrant boxe's php?
thanks
If you use Vagrant, you need to set all variables there. To do this, you need to use SSH. You can try built-in vagrant ssh command or any SSH client for Windows (WinSCP for example, connect and then press Ctrl+T for WinSCP Terminal).
Default credentials for vagrant ssh are:
Host: 127.0.0.1
Login: vagrant
Password: vagrant
Port: 2222

SSH using NetBeans to Ubuntu

I want to edit a website hosted on Ubuntu 12.04 Server from Windows 8.1 through NetBeans 7.3.1 using SSH
I tried this but getting this error.
I can successfully SSH to that Ubuntu machine through other PCs.
This issue is not related to NetBeans. Host Name ubuntu provided is not a valid hostname.
Try running this command on Command Prompt (cmd):
ping ubuntu
It will most likely return with this error message:
Ping request could not find host ubuntu. Please check the name and try again.
It works on other PCs you mentioned in the question because:
They have the host in their hosts file (C:\Windows\System32\drivers\etc\hosts). E.g:
192.168.0.16 ubuntu
They are using different DNS servers
You can get the IP address of the Ubuntu machine by logging into it and getting the IP address from the response of the following command:
ifconfig
You can update your hosts file using the IP.

mysql is not responsing on xampp

I am using XAMPP server for my php/mysql projects. Today, when I tried to start apache and mysql, mysql failed to open saying "this may be due to a blocked port, missing dependencies, improper privileges...", and my phpmyadmin page says "#2002 - No connection could be made because the target machine actively refused it."
I am nervous because I have an important database there and I cannot open it nor I have a backup of it. I am looking for your valuable comments.
p.s. I have installed Python version 2.7.6 yesterday. Can Python block the default mysql port 3306?
I am on windows 7 os
use
netstat -b -p TCP
to view the process is using port 3306

Categories