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.
Steps 1-3 must be run as root as they are installing the mongodb PHP module system-wide. Step 4 should be run using your domain’s “System User” account. If you opt to complete step 4 as root, be sure to chown the files to the correct user after you’re done.
0. Set up MongoDB Server Daemon if you haven’t already
yum install mongodb-org-server service mongod restart
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
3. Enable mongodb
Insert the following in /opt/plesk/php/7.0/etc/php.d/mongodb.ini [note: the file may not yet exist]
4. 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"
This guide uses the Plesk PHP7 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 and selected for the domain in question in Plesk’s GUI.