← ServerPilot Docs

How to Install the PHP SSH2 Extension

In the examples shown, replace "X.Y" with your app's PHP version (for example, "7.4" or "8.4"). To install a PECL extension for multiple PHP versions, repeat the PECL extension installation for each PHP version.

The SSH2 extension provides functions for accessing remote machines using the secure SSH and SFTP protocols.

Installing the SSH2 Extension on PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, or 8.4

Note: The SSH2 extension's support for PHP 7.x and 8.x is currently in beta.

To install this extension on PHP 7+, SSH in as root and run the following commands on your server:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libssh2-1-dev
yes '' | sudo peclX.Y-sp install ssh2-beta

Once installed, create a configuration file for the extension and restart PHP.

sudo bash -c "echo extension=ssh2.so > /etc/phpX.Y-sp/conf.d/ssh2.ini"
sudo service phpX.Y-fpm-sp restart

Installing the SSH2 Extension on PHP 5

To install this extension on PHP 5.6, SSH in as root and run the following on your server:

sudo apt-get install gcc make autoconf libc-dev pkg-config
sudo apt-get install libssh2-1-dev
sudo pecl5.6-sp install ssh2

Once installed, create a configuration file for the extension and restart PHP.

sudo bash -c "echo extension=ssh2.so > /etc/php5.6-sp/conf.d/ssh2.ini"
sudo service php5.6-fpm-sp restart

Verifying the Installation

You can verify the SSH2 extension is installed with the command:

phpX.Y-sp -i | grep ssh2

If SSH2 is installed correctly, you will see the following:

/etc/phpX.Y-sp/conf.d/ssh2.ini,
Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php,
    file, glob, data, http, ftp, zip, phar, ssh2.shell, ssh2.exec,
    ssh2.tunnel, ssh2.scp, ssh2.sftp
ssh2
SSH2 support => enabled
libssh2 version => 1.4.3
banner => SSH-2.0-libssh2_1.4.3

Uninstalling the SSH2 Extension

To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/ssh2.ini
sudo peclX.Y-sp uninstall ssh2

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart
Last updated: October 28, 2024

Launch your first site in 5 minutes