views:

102

answers:

2

Is it possible to execute shell commands on a remote computer (not localhost)? For instance things like

$output = shell_exec("unzip filename.zip");

You can assume that you have the login credentials of a user account on the remote machine, as well as the remote root username, password, and cpanel remote access key.

A: 

Yes, and there is no need to change any code to do so. However, if your server puts PHP into safe mode (the lesser shared hosting plans often do) you may not be able to do this.

Tip: You can use this shorthand to get the output of a command:

$output = `command here`
Delan Azabani
A: 

If you mean "a remote computer" as in "not the client computer", the answer is an unqualified yes; commands run via PHP's exec function will execute on the web server.

If you mean "not the web server", the answer is a slighty-hazier yes. You can only directly execute commands on the server running PHP. However, those commands can then run others on remote machines via mechanisms such as SSH. So, for example, if your web server has passwordless ssh access to the remote machine (a very bad idea), this would work: exec('ssh otherhost someremotecommand');. What solution fits for you depends on your desired usage.

Borealid