php 如何安装phpseclib?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30515751/
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
How to install phpseclib?
提问by Diego
I have installed Apache on my machine so I can use localhost as a PHP server. That works. Right now I am trying to use PHP to send files via SFTP to another server. I looked around a bit and saw phpseclib was recommended. I can't seem to figure out how to install phpseclib. Here are the lines that the website gave:
我已经在我的机器上安装了 Apache,所以我可以使用 localhost 作为 PHP 服务器。那个有效。现在我正在尝试使用 PHP 通过 SFTP 将文件发送到另一台服务器。我环顾四周,看到推荐使用 phpseclib。我似乎无法弄清楚如何安装 phpseclib。以下是该网站给出的行:
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('Net/SFTP.php');
You have to set the include path.
您必须设置包含路径。
I understand what these words mean but I have been unable to get it working. I am using a mac. My server is in /Users/diego/Sites/
. Where exactly do I need to put the phpseclib
folder? What lines do I need to put in my php file so that phpseclib
is included?
我明白这些话的意思,但我一直无法让它发挥作用。我正在使用 mac。我的服务器在/Users/diego/Sites/
. 我到底需要把phpseclib
文件夹放在哪里?我需要在我的 php 文件中放入哪些行才能phpseclib
包含在内?
采纳答案by Diego
I got it working by installing PEAR, following this guide.
By following the guide above, I figured out that apache2 was looking for php.ini
in my /etc/
folder. But I ran into a problem. In my /etc/
folder there was no php.ini
file. But there was php.ini.defualt
. So I 'saved as' php.ini.default
to php.ini
and then modified the include_path.
按照上面的指南,我发现 apache2 正在php.ini
我的/etc/
文件夹中寻找。但是我遇到了一个问题。在我的/etc/
文件夹中没有php.ini
文件。但是有php.ini.defualt
。所以我“另存为”php.ini.default
对php.ini
,然后进行修改和include_path。
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
include_path = ".:/Users/diego/pear/share/pear:/php/includes"
PHP is no longer throwing an error saying that phpseclib
cannot be found.
PHP 不再抛出phpseclib
无法找到的错误。
回答by Krishna
I tried installing phpseclib on linux machine. It worked perfectly for me. I hope you need a similar configuration on your Mac.
我尝试在 linux 机器上安装 phpseclib。它非常适合我。我希望你的 Mac 需要类似的配置。
On linux server execute following command.
在 linux 服务器上执行以下命令。
sudo apt-get install php5-pgsql php-pear
sudo pear channel-discover phpseclib.sourceforge.net
sudo pear remote-list -c phpseclib
sudo pear install phpseclib/Net_SSH2
sudo service apache2 restart
On Mac, using mac port execute following command sudo port -v selfupdate sudo port install php54-ssh2
在 Mac 上,使用 mac port 执行以下命令 sudo port -v selfupdate sudo port install php54-ssh2
#add this to the php.ini file /etc/php.ini, it can be placed at the end of the file
extension=/opt/local/lib/php54/extensions/no-debug-non-zts-20100525/ssh2.so
sudo /usr/sbin/apachectl restart
On Mac, using homebrew execute following command. brew install php54-ssh2
在 Mac 上,使用自制软件执行以下命令。酿造安装php54-ssh2
Download phpseclib library and include into your project directory.
下载 phpseclib 库并将其包含到您的项目目录中。
In the relevant php file add following code.
在相关的 php 文件中添加以下代码。
include('phpseclib1.0.5/Net/SFTP.php');
set_include_path(get_include_path().PATH_SEPARATOR.'phpseclib');
define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
$sftp = new Net_SFTP('555.55.55.55', 22);
if(!$sftp->login('username', 'password')) {
echo $sftp->getSFTPLog();
die('Login failed!');
} else {
echo $sftp->pwd();
echo $upload = $sftp->put('/sftp/'.$filename, $uploadedfile, NET_SFTP_LOCAL_FILE);
}
回答by KnockDown
Thanks to Diego, for the hint to install PEAR. I got it working with the following steps:
感谢 Diego 提供安装 PEAR 的提示。我通过以下步骤得到了它:
First, install PEAR.
首先,安装PEAR。
$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar
If the wgetcommand doesn't work, please install that package, to get it working.
如果wget命令不起作用,请安装该软件包以使其正常工作。
$ sudo apt-get install wget
After successfully installing PEAR, configure it with this guide.
成功安装 PEAR 后,使用本指南对其进行配置。
The php.ini
file, can be found in /etc/php5/apache2
. You have to modify this file.
该php.ini
文件,可以在/etc/php5/apache2
. 您必须修改此文件。
Suddenly, I tested the new libary. But I got a bunch of error's instead, like in this stackoverflow postdescribed. For that issue, I got the solution for it, in this stackoverflow post.
突然间,我测试了新库。但是我得到了一堆错误,就像在这篇stackoverflow帖子中描述的那样。对于这个问题,我在这个stackoverflow post 中找到了解决方案。
回答by neubert
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
will add phpseclib as a relative path. So doing include('Net/SFTP.php')
will include phpseclib/Net/SFTP.php
but that's relative to whatever your working directory is.
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
将 phpseclib 添加为相对路径。这样做include('Net/SFTP.php')
将包括phpseclib/Net/SFTP.php
但这是相对于您的工作目录的任何内容。
PEAR often has an absolute path in the include_path. So that's something you could try doing. Putting phpseclib in some directory (prob outside of the document root) and then putting that directory into your include_path.
PEAR 通常在 include_path 中有一个绝对路径。所以这是你可以尝试做的事情。将 phpseclib 放入某个目录(文档根目录之外的 prob),然后将该目录放入您的 include_path 中。
Note that this matters more if you downloaded phpseclib from sourceforge.net or if you're on the 1.0 branch.
请注意,如果您从 sourceforge.net 下载了 phpseclib 或者您在 1.0 分支上,这会更重要。