如何使用php脚本或php shell客户端重新启动远程专用服务器


How to reboot a remote dedicated server using php script or php shell client?

我正在研究一种使用php重新启动远程专用服务器的方法。在谷歌上做研究时,我读到了关于Pythonshell客户端的文章。php中有类似的东西吗?

我可以使用php使用shell命令重新启动远程服务器吗?需要什么来做到这一点?

我假设您想要一个在php中实现的基于web的shell。在这种情况下,你可以看看这个http://ajaxshell.sourceforge.net/这个http://sourceforge.net/projects/ajaxshell/

使用这些脚本,您可以运行任意的shell命令。但要记住两件事。1.密码保护web shell应用程序2.shell将作为apache用户运行命令。如果您想重新启动服务器,apache可能需要root权限。以root身份运行apache通常被认为不是一个好的做法。

你可能可以,通过使用exec()、passthru()等。我不确定这是个好主意吗:你必须给你的php用户重新启动权限(我不知道确切的,但它几乎是root…)。

可以肯定的是,你想做的是调用一个网页来重新启动你的服务器,或者这更复杂?

PHP有一个shell等价物。我最近发布了一个项目,允许PHP获得一个真正的Bash shell并与之交互,你甚至可以轻松地获得一个带有root的shell。在这里获取:https://github.com/merlinthemagic/MTS

下载后,您只需使用以下代码:

//if PHP is running on the server you want to reboot:
$shell    = 'MTS'Factories::getDevices()->getLocalHost()->getShell('bash', true);
//if PHP needs to SSH to the server first
$shell = 'MTS'Factories::getDevices()->getRemoteHost('ip_address')->getShellBySsh('username', 'password');
$strCmd = "reboot";
$return1  = $shell->exeCmd($strCmd);