Phew. I’ve just succeeded in installing SSH2 on my DreamHost hosting account, which happens to run on Debian. I am more of a Windows guy which explains why it took me so long but I am none the wiser for the experience. Let me show you how I did it. I used these two excellent articles as my points of reference:
First of all, let it be said that I am running on PHP 5.3. So if you are using DreamHost as your hosting provider, follow this guide here to update your account:
If you are already running 5.3 you might want to skip a few of these steps down and read ahead:
Upgrading to PHP 5.3
PHP 5.3 supports several new configuration hooks which make custom php.ini configuration super-easy! DreamHost recommends that all users needing custom PHP setup use PHP 5.3 or later, as the configuration changes required to set it up are much simpler than for PHP 5.2.
Log into the panel at https://panel.dreamhost.com/index.cgi?tree=domain.manage& and change your domain to use php5.3 (probably fast cgi)Create a directory under your user called .php, with a subdirectory called 5.3. Files under this directory will be used by all domains under that user which are set to use PHP 5.3. Example for the terminal mkdir ~/.php
mkdir ~/.php/5.3 Once this directory exists, there are two files you can create in it: To add custom directives to PHP, create a file under .php/5.3/ called “phprc” and add configuration directives to it. You do not need to copy the default php.ini to this file, as it is used in addition to the system php.ini; if a directive appears in both files, the one in this file will take precedence. nano phprc and then type in the commands you need. Sample directive which turns off error reporting level Notice and Deprecated error_reporting = E_ALL & ^(E_DEPRECATED|E_NOTICE) Replace the system php.ini entirely To replace the system php.ini entirely, create a file under .php/5.3/ called “phpini”. If this file exists, PHP will not read the system php.ini at all, so you should probably start by copying /etc/php53/php.ini here as a starting point. In most cases, this file is not necessary — please use a phprc if at all possible.
You may need to force PHP to reload its configuration file for changes to take effect. You can do this by running “killall php53.cgi” from a shell, or by waiting several minutes. Loading PHP 5.3 extensions Our build of PHP 5.3 contains a number of additional extensions which are not loaded by default (for instance: soap). You can load them by simply adding the following line to a file at /home/username/.php/5.3/phprc: extension = soap.so
That last paragraph about loading php5.3 extensions is important because that’s exactly what we will do once we build and compile the ssh2 extension. For the mean time, make sure you are running PHP 5.3 by typing the command “which php” which should give you something like /usr/local/etc/php53. Your mileage might vary. If it still says /usr/local/etc/php5 on Dreamhost, you are still running 5.2.
Libraries Needed
Once you are running 5.3, the next step would be to download the necessary files you will need to compile and install. Download the archives for LibSSH and SSH2. I have used:
Once downloaded, I uploaded them manually to a “src” folder on my server and unzipped them. You could use the wget command to download the files, you know, pack it all up nice in a shell script(Try this script on your machine, make sure you edit the values for PHPDIR and PREFIXDIR, specially for PHPDIR, make sure it points to your PHP 5.3 installation) but for some reason, it did not work for me. I just ran the following commands manually:
#Keep in mind I am using the following values for the {} variables you are seeing below SRCDIR=${HOME}/src PHPDIR=usr/local/etc/php53 PREFIXDIR=${HOME}/sshprefix LIBSSH2="libssh2-1.8" LIBSSH2FEATURES="--prefix=${PREFIXDIR}" SSH2="ssh2-0.11.2" SSH2FEATURES="--prefix=${PREFIXDIR} --with-php-config=${PHPDIR}/bin/php-config --with-ssh2=${PREFIXDIR}" # Push the install dir's bin directory into the path. Important step not miss export PATH=${PREFIXDIR}/bin:$PATH export PHP_PREFIX=${PHPDIR}/bin # Extract the src files into the src directory. cd ${SRCDIR} tar xzf ${SRCDIR}/${LIBSSH2}.tar.gz tar xzf ${SRCDIR}/${SSH2}.tgz ## Compile #AUTOCONF cd ${SRCDIR}/${AUTOCONF} ./configure --prefix=${PREFIXDIR} make install #LIBSSH2 cd ${SRCDIR}/${LIBSSH2} ./configure ${LIBSSH2FEATURES} make all install #SSH2 cd ${SRCDIR}/${SSH2} $PHP_PREFIX/phpize ./configure make
Once this is done, your ssh2.so extension file should be avaible in the {SRCDIR}/ssh2-0.11.2/modules directory. What is important to remember for installing on DreamHost shared account is that since you don’t have access to the system’s regular folder, you need to specify a prefix directory to append to the path to support all the libssh and ssh2 related commands. That’s a very important step to complete. Copy the file to the .php/5.3 folder you created earlier and edit your phprc file to :
cp ~/src/ssh2-0.11.2/modules/ssh2.so !/.php/5.3
Edit your phprc file also to load the ssh2.so extension
extension=ssh2.so
Verify that the ssh2 extension was loaded by entering in the command line:
php -m
You should see the ssh2 extension loaded in the list. That’s it. You are free now to return to your code and use SSH2 connections to your liking!
Hope It Helps!
Leave a Reply