PHP Warning: PHP Startup: Unable to load dynamic library ‘ssh2.so’

I have a WordPress Website and recently I decided to upgraded my PHP to 7.2

When I upgraded PHP from version 5.4 to version 7.2 on my CentOS 7 having apache as a web server and since I was using an external server (disk space of different machine like CDN but located at only one location) for media resources. I use to copy all the media from WP’s uploads folder to this remote server which is in the same network using SSH connection, So after upgrade whenever I use to upload an image it never got uploaded as PHP was unable to load SSH2 library, got below fatal error

PHP Fatal error:  Uncaught Error: Call to undefined function ssh2_connect() in ...

To copy every image uploaded to upload’s folder to a remote server within same network use

ssh2_connect
http://php.net/manual/en/function.ssh2-connect.php

Below is the error I use to get every-time I checked php version

$ php -v
PHP Warning:  PHP Startup: Unable to load dynamic library 'ssh2.so' (tried: /usr/lib64/php/modules/ssh2.so (/usr/lib64/php/modules/ssh2.so: undefined symbol: zval_used_for_init), /usr/lib64/php/modules/ssh2.so.so (/usr/lib64/php/modules/ssh2.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.2.15 (cli) (built: Feb  5 2019 19:50:47) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
locate ssh2.so
  • Save
locate ssh2.so
ssh2 extension check
  • Save
ssh2 extension check

Also Checked if PHP SSH2 extension/module was already installed from CentOS repo, It was not in my case so installed it using below command

$ sudo yum install php-ssh2
sudo yum install php-ssh2
  • Save
sudo yum install php-ssh2

The installation was successful with some warnings

PHP Warning: Module 'ssh2' already loaded in Unknown on line 0
PHP version check
  • Save
PHP version check

Checked if PHP list of module had SSH2

php -m
  • Save
php -m

After some research finally found out that in /etc/php.d there were 2 ssh2.ini files which were getting loaded every time any PHP function/command.

/etc/php.d
  • Save
/etc/php.d

In the above image, you can see ssh2.ini are backed-up with different names whereas only 40-ssh2.ini module is kept as it is.

PHP version check
  • Save
PHP version check after renaming/removing extra ssh2.ini module

And IT WORKED!!!

About the author

Rohan Kamble

I am a Web Developer by profession, who loves the web to the core with over 8 Years of Experience on working a wide range of domains like websites on e-commerce, matrimonial, company’s professional sites, Finance, company internal communications and many more…

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.