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.
- Log in to your server over SSH as root.
- 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.
- 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.
- 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.
- Restart your web server.
systemctl restart httpd
- Check that it works.
php -m | grep ssh2
If you see the word ssh2, the install worked.
Steps on Ubuntu or Debian
- Run
apt update. - Install the extension with
apt install php-ssh2. - Restart Apache with
systemctl restart apache2. - Check again with
php -m | grep ssh2.
<?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.