为 PHP 安装 PECL SSH2 扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/561024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install PECL SSH2 extension for PHP
提问by Cédric Girard
I am trying to install this http://fr2.php.net/manual/en/book.ssh2.phpon a Centos 5 (a fork of RHEL 5).
我正在尝试 在 Centos 5(RHEL 5 的一个分支)上安装这个 http://fr2.php.net/manual/en/book.ssh2.php。
I installed libssh2 (yum install libssh2) wich is located in /usr/lib, and when I install SSH2 extension (via pecl install -f ssh2) I get this message
我安装了位于 /usr/lib 中的 libssh2(yum install libssh2),当我安装 SSH2 扩展(通过 pecl install -f ssh2)时,我收到此消息
checking for ssh2 files in default path... not found configure: error: The required libssh2 library was not found. You can obtain that package from http://sourceforge.net/projects/libssh2/ERROR: `/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr' failed
检查默认路径中的 ssh2 文件...未找到配置:错误:找不到所需的 libssh2 库。您可以从http://sourceforge.net/projects/libssh2/获取该包 错误:`/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr' failed
If I set /usr/lib, I get the same message
如果我设置 /usr/lib,我会收到相同的消息
ERROR: `/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr/lib' failed
错误:`/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr/lib' 失败
Where is the problem?
问题出在哪儿?
回答by Cédric Girard
Installing libssh2 via tar.gz from http://sourceforge.net/projects/libssh2/help a lot (--with-ssh2=/usr/local/include/).
通过来自http://sourceforge.net/projects/libssh2/ 的tar.gz 安装 libssh2有很大帮助(--with-ssh2=/usr/local/include/)。
But "yum install libssh2-devel" is a better idea.
但是“yum install libssh2-devel”是一个更好的主意。
回答by serghei
$ sudo pecl channel-update pecl.php.net
$ sudo apt-get install libssh2-1-dev
$ sudo pecl install -a ssh2-0.12
$ echo 'extension=ssh2.so' | sudo tee /etc/php5/mods-available/ssh2.ini > /dev/null
$ sudo php5enmod ssh2
回答by vladkras
yum install libssh2-develdidn't work for me:
yum install libssh2-devel对我不起作用:
No package libssh2-devel available.
没有可用的软件包 libssh2-devel。
So I downloaded rpm package from rpmfindand installed with rpm -ivh
所以我从rpmfind下载了 rpm 包并安装了rpm -ivh
After that just added extension=ssh2.soto /etc/php.d/ssh2.ini
之后刚刚添加extension=ssh2.so到/etc/php.d/ssh2.ini
回答by user151841
I'm running on Centos, none of these answer were the entire solution for me. I followed these instructions:
我在 Centos 上运行,这些答案都不是我的完整解决方案。我遵循了以下说明:
$ sudo yum install -y gcc php-devel php-pear libssh2 libssh2-devel
But php-develwould not install, complaining about conflicts. I searched yum to find what php devel packages I had available
但php-devel不会安装,抱怨冲突。我搜索 yum 以找到我可用的 php devel 包
$> yum search php|grep devel
...
php55u-devel.x86_64 : Files needed for building PHP extensions
php56u-devel.x86_64 : Files needed for building PHP extensions
php70u-devel.x86_64 : Files needed for building PHP extensions
...
So I ran
所以我跑了
$> sudo yum install -y php56u-devel
And it installed cleanly. Then, continuing with the instructions, I ran
它安装得很干净。然后,继续按照指示,我跑了
$ pecl install -f ssh2
And it compiled. Then I added the extension to php
它编译。然后我将扩展添加到 php
$ touch /etc/php.d/ssh2.ini
$ echo extension=ssh2.so > /etc/php.d/ssh2.ini
And on my system, instead of
而在我的系统上,而不是
$ /etc/init.d/httpd restart
I had to do
我必须做
$ sudo /bin/systemctl restart php-fpm.service
So that was all the steps to install. And finally to confirm:
这就是安装的所有步骤。最后确认:
$> php -m|grep ssh2
ssh2
回答by Tomasz
This is updated answerfrom @klay + modification from @avn from comment under working solution for PHP 7.x.
这是来自 @klay 的更新答案+ 来自 @avn 的修改来自PHP 7.x工作解决方案下的评论。
$ sudo pecl channel-update pecl.php.net
$ sudo apt-get install libssh2-1-dev
$ sudo pecl install -a ssh2-1.0
$ echo 'extension=ssh2.so' | sudo tee /etc/php/7.2/mods-available/ssh2.ini > /dev/null
$ sudo phpenmod ssh2
Regarding line:
关于线路:
echo 'extension=ssh2.so' | sudo tee /etc/php/7.2/mods-available/ssh2.ini > /dev/null
Make sure that path /etc/php/7.2/mods-availableis valid and there is a match with your php version.
确保路径/etc/php/7.2/mods-available有效并且与您的 php 版本匹配。
回答by Mighty
I had this problem:
我有这个问题:
I'm on a Pair.com "Advanced" hosted account, so I'm a little limited on what I'm allowed to do. I don't think I can yumnor aptitudenor any of the other pre-compiled packages.
我使用的是 Pair.com“高级”托管帐户,因此我的权限有限。我认为我不能,yum也不能aptitude或任何其他预编译包。
I've downloaded and compiled libssh2. During the peclprocess, it asks where the library is located. It's in "~/usr/local/lib" and I've tried several variations, including fully qualified. But I kept getting the same error.
我已经下载并编译了 libssh2。在此pecl过程中,它会询问库所在的位置。它在“~/usr/local/lib”中,我尝试了几种变体,包括完全限定的。但我一直收到同样的错误。
The error message doesn't spell out precisely which file it's looking for. libssh2.so is in that directory. I know the output is supposed to be ssh2.so. I wondered if there is supposed to be an ss2.something, or libssh.nothing?
错误消息没有准确说明它正在寻找哪个文件。libssh2.so 位于该目录中。我知道输出应该是 ssh2.so。我想知道是否应该有一个 ss2.something 或 libssh.nothing?
I fixed it thus. In my case, after compiling libssh2 I downloaded the PEAR tarball. The trick was:
我是这样修的。就我而言,在编译 libssh2 后,我下载了 PEAR tarball。诀窍是:
./configure --with-ssh2=<libssh2 location> --prefix=<libssh2 location>
Another trick is that, since Pair.com is running FreeBSD, I have to do a "cd ." after the ./configure command. Otherwise, make produces a "Permission denied" error. Apparently, this is necessary on all *nix BSD flavors.
另一个技巧是,因为 Pair.com 运行的是 FreeBSD,所以我必须做一个“cd”。在 ./configure 命令之后。否则,make 会产生“权限被拒绝”错误。显然,这对所有 *nix BSD 风格都是必要的。

