Compiling PHP_SSH2 support

by earnest on Fri, 10/26/2007 - 03:01

While working on the Autopilot system, I choose to use the php_ssh2 library, which uses the libssh2 library to issue/implement ssh commands. With this module loaded (http://www.php.net/ssh2), one can act as an SSH2 client in php!

Well, as many of you know, I work off of a Windows system for development ( a highly modified windows installation ;)). So, to enable, I just "enabled" the php_ssh2 lib. Easy enough right? WRONG! For this blog entry, I will discuss issues with BOTH implementations of this seemingly troublesome module.

 

Systems ( general information about systems and versions):
  • PHP 5.2
  • Windows XP Pro SP2
  • Linux (CentOS 4)

 

Windows

Yes, I'm talking about windows first. The other 95% of you can go ahead and scroll down to the linux section where I talk about compiling the module from source.


After I enabled the windows module, I kept getting errors in my php log saying that the module could not be found. I didn't know what was going on? I had OpenSSL installed, the openssl module enabled, and still, I got errors? Well, it seems that there is a problem and some type of conflict with Apache under windows when running this module, thus why the errors appeared. The errors ONLY appear when you try and enabled the module in your php.ini file, OR if you try to dynamically load the module in your php code (e.g. via the dl function [http://www.php.net/dl]). BUT, the error does NOT appear, and the module loads fine IF you load it in from a CLI script.

So, to summarize:

  • php_ssh2 module will currently not load and throw errors if enabled in your php.ini file.
  • php_ssh2 module will currently not load if you attempt to load it via the "dl" function.
  • php_ssh2 module WILL load from php CLI script

I thus had to a slick work around, bascially calling my CLI script from my PHP code to load the lib and do my dirty work :).

Linux

Linux is a different bear. The module loads fine from the php.ini file, the problem is getting the module. Most of the repos I found only had libssh2 version .1x. The php documentation specifically says that:

"Requires libssh2 version .4 or higher"

So, I then turned to compiling the module from source. I downloaded the libssh2 module from sourceforge. I ran my commands (./configure && make install ), and figured I was off and running. I then turned to php to compile/load my php_ssh2.so module. However, when i did "pecl install ssh2-beta" (and you MUST use ssh-beta as there is currently NOT a stable version), I kept getting errors.

Well, it seems that the make file needs to be patched in order to compile correctly ( the patch is attached to this blog post ).

So, in summary:

Compiling From Source

  1. Download libssh2
  2. Install libssh2
    1. Navigate to the libssh2 folder that you just downloaded.
    2. Run: ./configure
    3. Run: make install
  3. Either download the php_ssh2 source from PECL, or run "pecl isntall ssh2-beta" to have the files downloaded for you.
  4. Download the patch
  5. Patch your ssh2.c file with the patch
  6. Run either of these commands:
    1. (PECL/PEAR method): pecl install ssh2-beta
    2. (Manual) Navigate to the php_ssh2 folder where you patched ssh2.c and run:
      phpize && ./configure && make ssh2
  7. The php_ssh2.so will be outputed to the modules folder
  8. Copy the php_ssh2.so to your php module folder
  9. Enable the php_ss2.so in your php.ini file

 

Happy Halloween! :)

Tags: apacheautopilotconceptsDevelopmentinstallationpatches

earnest's blog  
    Delicious  Digg  Reddit  Technorati  

Comments

Patch?

Where's the patch you mentioned in this blog?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options