This guide will help you install MongoDB’s PHP Extension on a Plesk server. You require root access to the server, so this is not compatible with shared hosting environments.
The last step should be run using your domain’s “System User” account.
This guide uses the Plesk PHP 7.0 binary, but you can replace all instances of “70” and “7.0” with your selected version of PHP. Just make sure that you’ve got that particular version installed (by Plesk) and selected for the domain in question in Plesk’s GUI, otherwise the web app will not find the mongodb server.
0. Install MongoDB Server Daemon if you haven’t already
echo '[MongoDB] name=MongoDB Repository baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc' > /etc/yum.repos.d/mongodb.repo yum install mongodb-org systemctl restart mongod
1. Install dependencies for compiling
yum install gcc openssl-devel plesk-php70-devel
2. Use PECL to install PHP library
/opt/plesk/php/7.0/bin/pecl config-set php_prefix /opt/plesk/php/7.0/bin/ /opt/plesk/php/7.0/bin/pecl install mongodb echo 'extension=mongodb.so' > /opt/plesk/php/7.0/etc/php.d/mongodb.ini systemctl restart plesk-php70-fpm
3. Set up mongodb library using Composer
Note that you must have composer installed in the file path where you wish to run/use it before running this command.
/opt/plesk/php/7.0/bin/php composer.phar require "mongodb/mongodb=^1.0.0"
If you completed this final step accidentally as root, be sure to chown the files to the correct user after you’re done.