Installing mongodb for PHP on Plesk servers

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
gpgkey=' > /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 '' > /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.

Did you find this guide helpful? Check out our blog for more great information. Need more help? With one of our managed Canadian VPS services, we can handle the installation for you!

About Jordan Schelew

Jordan has been working with computers, security, and network systems since the 90s and is a managing partner at Websavers Inc. As a founder of the company, he's been in the web tech space for over 15 years.


  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!


    • 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