Installing SSH2 for PHP on a Media Temple DV Server

Disclaimer

These notes follow the general instructions on PHP’s SSH2 installation page. They also cover some critical details for installation on a Media Temple DV 3.5 server. The notes on this page are provided as-is, and are not guaranteed to work on your server. Please use them as a guideline and, if you don’t understand what you’re doing, get someone experienced to help you.

Enabling Root Access & Developer Tools

The installation process requires root access to your machine and developer tools to be installed. To do this:

  • In the (mt) Account Center, select your primary domain and navigate to Root Access & Developer Tools
  • Enable root access and set a root password
  • Install developer tools (this might take a few minutes to complete—be patient and make sure this shows as Installed before continuing)

Installing Yum and libssh2

Next, you will need to SSH in to your server. If you don’t have an SSH client, you can use PuTTY. You’ll need to install the Yum package manager and libssh2 first:

  • Install Yum:
    rpm -Uvh http://mirror.centos.org/centos/5/os/i386/CentOS/python-iniparse-0.2.3-4.el5.noarch.rpm
    rpm -Uvh http://mirror.centos.org/centos/5/os/i386/CentOS/yum-3.2.8-9.el5.centos.1.noarch.rpm
    

    Note: Versions are subject to change so you may need to browse the mirror for the appropriate version number.

  • Install libssh2 and libssh2-devel packages:
    yum install libssh2
    yum install libssh2-devel
    

Installing the SSH2 Extension

Now we can start working on getting the SSH2 extension installed:

  • Set environmental variables:
    export PHP_AUTOCONF=autoconf
    export PHP_AUTOHEADER=autoheader
    
  • Mount the temp path as executable:
    mount -oremount,exec /var/tmp
    
  • Perform the install. Use the -f switch to force the install of the beta package, as a stable version does not exist at the time of this writing:
    pecl install -f ssh2
    
The latest tarball (as of this writing) has an issue and it may not compile correctly. If the previous step ends in something like make: *** [ssh2.lo] Error 1 error, you will need to perform the following patch:

  • Extract the files from the tarball
  • Edit ssh2.c and look for: #if LIBSSH2_APINO < 200412301450
  • Change the line to look like: #if LIBSSH2_VERSION_NUM < 0×001000
  • Run the following commands:
    phpize
    ./configure --with-ssh2
    make
    make install
    
  • Once the install has completed, remember to make the temp path non-executable again:
    mount -oremount,noexec /var/tmp
    
  • Make sure that ssh2.so exists in /usr/lib/php/modules. If not, you’ll have to copy it to that directory from the build location.
  • Add extension=ssh2.so to your php.ini file (located at /etc/php.ini)
  • Restart apache (can be done via Plesk)

Verify the Installation

To verify that the extension was installed properly, you can use phpinfo() or you can check by executing a PHP script:

<?php
if( !function_exists('ssh2_connect') ) echo 'SSH2 is not installed';
?>
If you enjoyed this article, please share it with a friend!

One Response to Installing SSH2 for PHP on a Media Temple DV Server

  1. These ssh2 libraries are notoriously frustrating to use. We released a free wrapper class to smooth over a few kinks in the library and make common tasks easy. Hope this saves some people a rainy day ;)

    http://www.seoegghead.com/software/ssh2-php-wrappers.seo