1. Install ssh2 extension
(1)window
<span>1</span><span>. 下载 php extension ssh2 下载地址 http:</span>//windows.php.net/downloads/pecl/releases/ssh2/<span>0.12</span>/<span>根据自己PHP的版本去下载</span><span>2</span><span>. 解压完后,会有三个文件,libssh2.dll、php_ssh.dll、php_ssh2.pdb。 </span><span>3</span>. 将 php_ssh.dll、php_ssh2.pdb 放到你的 php 扩展目录下 php/ext/<span> 下。 </span><span>4</span>. 将libssh2.dll 复制到 c:/windows/system32 和 c:/windows/<span>syswow64 各一份 </span><span>5</span>. php.ini中加入 extension=<span>php_ssh2.dll </span><span>6</span><span>. 重启服务器,即可使用php执行ssh连接操作了。 查看phpinfo(),是否有显示php_ssh2扩展加载成功。<br></span>
(2)linux
<span>在linux下需要先安装扩展所需的依赖库 </span><span>1</span><span>.安装libssh2 wget http:</span>//www.libssh2.org/download/libssh2-<span>1.7</span>.<span>0</span><span>.tar.gz tar zxf libssh2</span>-<span>1.7</span>.<span>0</span><span>.tar.gz cd libssh2</span>-<span>1.7</span>.<span>0</span><span>.</span>/configure --prefix=/usr/local/<span>libssh2 make </span>&&<span> make install </span><span>2</span><span>.安装ssh2 wget http:</span>//pecl.php.net/get/ssh2-<span>0.12</span><span>.tgz tar </span>-zxvf ssh2-<span>0.12</span><span>.tgz cd ssh2</span>-<span>0.12</span><span>phpize .</span>/configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/<span>libssh2 make #执行完以上过程后,在当前目录下的modules目录下会生成一个ssh2.so文件,这就是扩展PHP所需要的,将该文件拷贝到PHP库的存储目录下在修改PHP的配置文件即可。 cp modules</span>/ssh2.so /usr/local/php/lib/php/extensions/no-debug-non-zts-<span>20131226</span>/<span>#注:PHP库的存储目录可能不同 vim </span>/usr/local/php/lib/<span>php.ini 添加extension</span>=<span>ssh2.so #重启php php </span>-m |grep ssh #可查看是否安装成功
2. The ssh2 extension is combined with svn to realize the update and deletion of file folders
( 1) Create the following directory
file to store the source code (co code is required for the first time, and then use up)
key to store the key
log to store error information, file update and delete records
svn Storage related operations (https://github.com/getCodeWarehouse/php_ssh2)
(2) Enable hooks in svn hooks,call php scripts
Important things to say I need to change the permissions three times~ I need to change the permissions~ I need to change the permissions~
svn up The status is U D A, use array_pop to pop up useless data
Update and new addition are the same category, you need to judge whether it is a file or a new one Folder, choose different functions, it is worth noting that ssh2_sftp_mkdir, if this folder exists on the remote machine, an error will be reported
The reason why you use the rm command to delete a folder is because ssh2_sftp_rmdir cannot delete non-empty folders, and it cannot add Parameters
(3) Test submission svn
Update file successfully
The above introduces the Php ssh2 extension application, including ssh and php content. I hope it will be helpful to friends who are interested in PHP tutorials.