Installing mongodb for PHP on Plesk servers

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]

extension=mongodb.so

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.

Jordan is a computer, security, and network systems expert and a lover of all things web and tech. Jordan consults with project management for software companies. Jordan is a founder and managing partner at Websavers Inc.

4 Comments

  1. diego on February 23, 2017 at 1:26 am

    Hi there i m getting pecl/mongodb requires PHP (version >= 5.4.0, version <= 7.99.99), installed version is 5.3.3
    buy we have 5.4 and 5.6 installed…but plesk for default

    PHP 5.3.3 (cli) (built: Aug 11 2016 20:33:53)
    Copyright (c) 1997-2010 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.6.0, Copyright (c) 2002-2014, by ionCube Ltd.

    Is like we cant uninstall de PHP OS base vendor

    Any idea why this ?

    • Jordan Schelew on February 23, 2017 at 12:04 pm

      Hi Diego,

      You basically can’t uninstall the OS base vendor version; it’s not so easy to do. Especially when you need a reliable repo that will be sure to update it with security patches, like OS vendors do with backports. But as this article describes, you *can* execute the Plesk binaries for newer versions of PHP instead. So do that!

      -Jordan

    • Giancarlo on May 3, 2017 at 11:17 pm

      Sorry for the necropost, but actually from the command line you can use the version of PHP-CLI that you want, and you can even change ini configurations on the fly (the one that comes in my mind is the memory limit, is very low).
      Simply recall it like that:

      /opt/plesk/php/5.6/bin/php -d memory_limit=512M yourcommand

      • Jordan Schelew on May 6, 2017 at 6:36 pm

        Hi Giancarlo,

        This is true, but I’m not sure what this has to do with using MongoDB?

Leave a Comment