0

I have a VPS with Debian 8 OS and a DirectAdmin panel with PHP7.2

To use MongoDB PHP driver, I installed it with the command sudo pecl install mongodb.

After that installation, I added the driver extension to the php.ini file by this command:

echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||" 

But it seems that driver not installed! Because when I exec a PHP command, face this warning:

PHP Warning: PHP Startup: Unable to load dynamic library 'mongodb.so' (tried: /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so (/usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so: cannot open shared object file: No such file or directory), /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so.so (/usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Everything is ok in my local (windows), I add the Non Thread Safe (NTS) driver extension to the extensions directory, and It's all!

What I did wrong? Is installation of MongoDB driver on the PHP of DirectAdmin different from installation on a normal PHP?

Update:

MongoDB is not in the result of phpinfo(); too!

Behnam Azimi
  • 2,260
  • 3
  • 34
  • 52
  • Does the file `mongodb.so` exist in the extension dir? Because the error says it does not. – Daniel W. Jun 28 '18 at 09:52
  • If you mean `/usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/`, No! there are just two files, `opcache.a` and `opcache.so` – Behnam Azimi Jun 28 '18 at 09:55
  • Yea so fix your `extension_dir` configuration and put the `.so` files in the appropriate folder, problem solved. – Daniel W. Jun 28 '18 at 11:59
  • I really don't know how should I do! where is the extension `.so` file, what do you mean fix! – Behnam Azimi Jun 28 '18 at 12:02
  • The `mongodb.so` file is installed in the extensions dir which is the one before you changed it..... what folders are in `/usr/local/php72/lib/php/extensions` ? Or simply use `find` and search for the file – Daniel W. Jun 28 '18 at 12:14
  • If the file does not exist and you change the extensions dir folder, how do you even expect it to work, of course mongodb is not loaded. – Daniel W. Jun 28 '18 at 12:15
  • but I did not change it before! only `no-debug-non-zts-20170718` is in the mentioned directory! – Behnam Azimi Jun 28 '18 at 12:17
  • When you install via pecl `sudo pecl install mongodb` it tells you where it did install to – Daniel W. Jun 28 '18 at 12:18
  • I just pressed Enter and let it default. and I did not see what you said – Behnam Azimi Jun 28 '18 at 12:19

2 Answers2

1

Please make sure php extension dir is: /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/

Check:

php -i |grep extension_dir

If not, there are two options to do it:

  1. modify extension_dir in php.ini to /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/
  2. echo "extension=/full_path_through_pecl_installed/mongodb.so" > php.ini
eaglewu
  • 458
  • 5
  • 12
  • the location is exactly what you mentioned. but how can I check that MongoDB extension is in there or any other valid directory that should be? It's just two files in that directory – Behnam Azimi Jun 28 '18 at 09:15
  • follow your update, please make sure that result of `php -i |grep extension_dir` and `phpinfo()` are the same. by the way make sure php cli `php.ini` and fpm `php.ini` are the same file. – eaglewu Jun 28 '18 at 11:14
  • after that warning, here is my result: `extension_dir => /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718 => /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718 sqlite3.extension_dir => no value => no value` – Behnam Azimi Jun 28 '18 at 11:15
  • 1
    fpm and php(cli) may use different `php.ini` – eaglewu Jun 28 '18 at 11:17
  • How should I check it? and also the values of phpinfo and that command are equal – Behnam Azimi Jun 28 '18 at 11:18
0

The issue was about DirectAdmin because it has its own PHP and extensions must add on it.

When I run sudo pecl install mongodb, It looks out default VPS PHP.

This command solved my problem:

cp /usr/lib/php/20170718/mongodb.so /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so
Behnam Azimi
  • 2,260
  • 3
  • 34
  • 52