Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

What Is SSH2 and How to Install It for PHP

SSH2 lets your PHP code talk to other servers in a safe way. This guide explains it and shows how to add it. You need root access.

Dedicated Servers2 min read10 steps

What is SSH2?

SSH means Secure Shell. It is a safe tunnel for sending commands and files to another computer. Everything inside the tunnel is scrambled, so nobody can read it on the way. SSH2 is version two of that protocol. A protocol is a set of rules two computers follow to talk.

The PHP SSH2 extension is an add-on. It lets your PHP scripts log in to another server, run commands and move files with SFTP. SFTP is a safe way to copy files. Some apps and backup tools need this add-on.

Steps on CentOS or AlmaLinux

These steps assume PHP is installed from the normal system packages. On a control panel server, the panel may have its own PHP tools, so ask Hostvento support first.

  1. Log in to your server over SSH as root.
  2. Install the tools you need to build the add-on.
yum install -y gcc make autoconf php-devel php-pear libssh2 libssh2-devel

This adds a compiler and the libssh2 library. A library is a box of ready code that other programs share.

  1. Install the extension with PECL, the PHP add-on installer.
pecl install ssh2

If it says no stable version is available, run pecl install ssh2-beta instead.

  1. Create a settings file so PHP loads it.
echo "extension=ssh2.so" > /etc/php.d/ssh2.ini

This writes one line that tells PHP to load SSH2.

  1. Restart your web server.
systemctl restart httpd
  1. Check that it works.
php -m | grep ssh2

If you see the word ssh2, the install worked.

Steps on Ubuntu or Debian

  1. Run apt update.
  2. Install the extension with apt install php-ssh2.
  3. Restart Apache with systemctl restart apache2.
  4. Check again with php -m | grep ssh2.
Tip: Create a file with <?php phpinfo(); ?> and open it in your browser. Search the page for "ssh2". Delete the file afterward, because it shows private details.

Quick recap

  • SSH2 is a safe, scrambled way to connect to another server.
  • The PHP ssh2 extension lets PHP use it.
  • On CentOS, install libssh2-devel and run pecl install ssh2.
  • On Ubuntu, install php-ssh2 with apt.
  • Restart the web server and check with php -m.