Reputation: 61
I am trying to enable mongodb on php:7.2-fpm-alpine, and I am not able to see the mongodb extension loaded in php.ini
Here is some additional info:
# mongo --version
MongoDB shell version v3.4.4
git version: 888390515874a9debd1b6c5d36559ca86b44babd
OpenSSL version: LibreSSL 2.5.5
allocator: system
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
and
# php -i | grep mongo
PHP Warning: PHP Startup: Unable to load dynamic library 'mongodb.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so.so: No such file or directory)) in Unknown on line 0
/usr/local/etc/php/conf.d/20_mongodb.ini,
Based on that warning I guess that the mongo extension is missing, but doesn't that conflict the info retrieved by the # mongo --version command?
I also tried to look for mongodb.so using find / -name 'mongo*.*'.
What is the best way to install and enable mongodb driver on php:7.2-fpm-alpine?
Update: Additional info when I run this command: # apk list -a | grep "mongo" I see: mongodb-3.4.4-r0 x86_64 {mongodb} (AGPL3) [installed]
Upvotes: 0
Views: 3718
Reputation: 61
After doing some more research and digging, I ended up installing PECL on the server.
Installing PECL on Alpine:
apk update && apk upgrade
apk add --no-cache php7-pear php7-dev gcc musl-dev make
Once PECL was installed, I ran this command:
sudo pecl install mongodb
after mongodb was installed I added "extension=mongodb.so" inside /usr/local/etc/php/conf.d/20_mongodb.ini
and finally I restarted the docker container.
After taking all these steps, I could see Mongodb installed and enabled by looking at phpinfo()
Now when I run:
php -i | grep mongo
I see
mongodb
libmongoc bundled version => 1.17.0
I am assuming the latest Mongodb(libmongoc) is the PHP package vs the "MongoDB shell version v3.4.4" which is the server level package.
I hope someone will find this information helpful.
Upvotes: 2