Site icon RohuTech

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

PHP Warning: PHP Startup: Unable to load dynamic library 'ssh2.so' - guy panic state seating in front of laptop

PHP Warning: PHP Startup: Unable to load dynamic library 'ssh2.so' - Photo by Sebastian Herrmann on Unsplash

This post will guide you to step by step solution on how to fix PHP Warning: PHP Startup: Unable to load dynamic library ‘ssh2.so’

I have a WordPress Website and recently I decided to 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 the 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
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

The installation was successful with some warnings

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

Checked if PHP list of the module had SSH2

php -m

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

/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 after renaming/removing extra ssh2.ini module

And IT WORKED!!!

Don’t forget to check my guides on ‘How to‘ queries here http://rohutech.com/category/guides/

Exit mobile version