SSH2 PHP extension for Plesk PHP 8

To install the PHP SSH2 extension under Plesk Obsidian for PHP 8, first log in to the Plesk server via SSH. Then execute the following commands:


Preparation

Additional packages must be installed to install the SSH2 extension:

apt update
apt install plesk-php80-dev plesk-php81-dev plesk-php82-dev plesk-php83-dev libssh2-1-dev gcc make


Before installing PHP extensions, a server snapshot should be created so that you can undo the installation with just a few clicks in the event of an error. Learn more →



Installation of the SSH2 extension

Carry out the installation using the pecl command:

/opt/plesk/php/8.0/bin/pecl install ssh2
/opt/plesk/php/8.1/bin/pecl install ssh2
/opt/plesk/php/8.2/bin/pecl install ssh2
/opt/plesk/php/8.3/bin/pecl install ssh2


After successful installation, the extension must be added to the PHP configuration:

echo "extension=ssh2.so" > /opt/plesk/php/8.0/etc/php.d/ssh2.ini
echo "extension=ssh2.so" > /opt/plesk/php/8.1/etc/php.d/ssh2.ini
echo "extension=ssh2.so" > /opt/plesk/php/8.2/etc/php.d/ssh2.ini
echo "extension=ssh2.so" > /opt/plesk/php/8.3/etc/php.d/ssh2.ini


To enable the new configuration via the Plesk web interface, the PHP 8 handler must be reloaded:

plesk bin php_handler --reread


The PHP handler must then be restarted in order to use the SSH2 extension:


Warning: Restarting the PHP modules will terminate and restart all running PHP processes. If the installation is carried out on a production system, we recommend making this change at night.


# PHP 8.0
systemctl restart plesk-php80-fpm

# PHP 8.1
systemctl restart plesk-php81-fpm

# PHP 8.2
systemctl restart plesk-php82-fpm

# PHP 8.3
systemctl restart plesk-php83-fpm



Verify installation

After successful installation, check whether the variables of the SSH2 extension are available:

/opt/plesk/php/8.3/bin/php -i |grep ssh2

/opt/plesk/php/8.3/etc/php.d/ssh2.ini,
Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp, zip
libSSH version => libssh2/1.9.0
ssh2
libssh2 version => 1.9.0
banner => SSH-2.0-libssh2_1.9.0


The SSH2 extension can then be used via FPM (Apache / nginx) or via CLI.