User Tools

Site Tools


wiki:software:linux:ssh2php

Linux: Installing SSH2 for PHP5

This article was originally published on December 12, 2008.

Deprecated

This method has been deprecated with the release of WordPress 3 – in Ubuntu/Debian, you now only need to run the following as root:

apt-get install libssh2-php
apache2ctl -k graceful

And you're done!

I just installed WordPress 2.7 today. Boy, is it exciting! The entire interface is different, and things can be accomplished much more quickly.

One of the neat features is the ability to add and remove plugins from the web interface. Unfortunately, WordPress only works with FTP and FTPS (FTP over SSL) by default. I don’t have an FTP server installed on my Linode, so I decided to see if I could use SSH instead.

Turns out it’s possible, but it sure was a beast to get up and running. I’ll go through what I did, in case anyone else had as much trouble with this as I did.

First off, you need to install PEAR. This is a nifty little utility that can automatically compile PHP extensions.

Keep in mind that I’m working in Ubuntu 8.04.1 here, and my Linode installation is very stripped down.

First, you need to install the command-line interface for PHP, which allows you to run PHP scripts from a terminal.

apt-get install php5-cli

Seeing as my installation of Ubuntu is devoid of pretty much any extras, I needed to install wget too.

apt-get install wget

Once that’s done, we can install PEAR.

cd /
wget http://pear.php.net/go-pear -O go-pear.php
php go-pear.php

Once the PEAR installation script is running, you need to configure the locations of each of the components. I chose to stick everything in /pear, but you may want to put it somewhere else. I’d recommend keeping option 3 to my setting, though.

1    /
2    /pear/temp
3    /bin
4    /pear
5    /pear/docs
6    /pear/data
7    /pear/tests

Now that PEAR is installed, we can get into installing OpenSSL and the necessary packages to make it work with PHP.

apt-get install openssl
apt-get install lsh-client
apt-get install libssh2-1
apt-get install libssh2-1-dev

With our libraries and packages installed, we can compile our ssh2 extension for PHP.

pecl install -f ssh2-beta

Finally, we need to add the extension to php.ini.

nano /etc/php5/apache/php.ini

Find the section titled Extensions and add this line:

extension=ssh2.so

And restart Apache:

apache2ctl -k graceful

In your WordPress admin interface, you should now see an “SSH” option when you go to add, remove, or update files on your server. WordPress provides text boxes to use your private and public SSH keys, but I found I only needed to use one of my user account’s credentials to authenticate to the server.