简体   繁体   English

使用 phpseclib 通过 SSH 运行 wp-cli 命令

[英]Running wp-cli commands through SSH with phpseclib

I am automating installing multiple WordPress blogs on a server.我正在自动在服务器上安装多个 WordPress 博客。 Basically, I need to run multiple wp-cli commands.基本上,我需要运行多个 wp-cli 命令。

Using phpseclib and doing exec() , doesn't work...使用 phpseclib 并执行exec() ,不起作用...

When I do something like:当我做这样的事情时:

$ssh->exec('wp core download');

I will just get:我只会得到:

/usr/bin/env: php: No such file or directory /usr/bin/env: php: 没有那个文件或目录

Even though I can run it fine, in a normal ssh session...即使我可以正常运行,但在正常的 ssh 会话中...

If I try and $ssh->write the command out and do '\\n' it doesn't seem to do anything.如果我尝试$ssh->write命令并执行 '\\n' 它似乎什么也没做。 Even if I just try to do a simple command like: touch foo.txt即使我只是尝试执行一个简单的命令,例如: touch foo.txt

Although that test "touch" command will work with exec...尽管该测试“触摸”命令将与 exec 一起使用...

The system is Ubuntu 14.04...系统是Ubuntu 14.04...

Any ideas?有任何想法吗?

I have to connect via SSH from PHP to do this for multiple domains on a server, as new customers come on.随着新客户的加入,我必须通过 PHP 的 SSH 连接才能为服务器上的多个域执行此操作。

The path to PHP probably needs to be defined.可能需要定义 PHP 的路径。 When you SH in with the regular SSH client it's probably running any number of Bash initialization files .当您使用常规 SSH 客户端 SH 时,它可能正在运行任意数量的Bash 初始化文件

In light of this I have two thoughts.有鉴于此,我有两个想法。

  1. Try to use a PTY.尝试使用 PTY。 eg.例如。

     $ssh->enablePTY(); $ssh->exec('passwd'); echo $ssh->read();

    More info: http://phpseclib.sourceforge.net/ssh/pty.html更多信息: http : //phpseclib.sourceforge.net/ssh/pty.html

  2. Are you doing $ssh->read('[prompt]');你在做$ssh->read('[prompt]'); after doing the write("command\\n") ?在执行write("command\\n") You may need to read the stream to get the command to actually be run.您可能需要读取流以获取实际运行的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM