Diadem Technologies Support Knowledgebase

Installing MongoDB for PHP on Plesk servers

Article ID: 989
Last updated: 08 Jul, 2021

MongoDB is an open source document-oriented database that provides high performance, high availability, and easy scalability. It is classified as a NoSQL database because it does not rely on a traditional table-based relational database structure. Instead, it uses JSON-like documents with dynamic schemas. Unlike relational databases, MongoDB does not require a predefined schema before you add data to a database. You can alter the schema at any time and as often as is necessary without having to setup a new database with an updated schema.

Step 1 – Adding the MongoDB Repository and Configure the package management system (yum)
The mongodb-org package does not exist within the default repositories for CentOS. MongoDB maintains a dedicated repository. Please create the repo file to install it.

# vim /etc/yum.repos.d/mongodb-org.repo

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc


Step 2 – Installing MongoDB

#yum install mongodb-org

# rpm -qa | grep mongo

mongodb-org-mongos-3.4.10-1.el6.x86_64
mongodb-org-server-3.4.10-1.el6.x86_64
mongodb-org-3.4.10-1.el6.x86_64
mongodb-org-shell-3.4.10-1.el6.x86_64
mongodb-org-tools-3.4.10-1.el6.x86_64

Start MongoDB services:
# service mongod start
# chkconfig mongod on

Summary List of Status Statistics
# mongostat
OR
# mongostat --rowcount 5 2
insert query update delete getmore command dirty used flushes vsize   res qrw arw net_in net_out conn                time
    *0    *0     *0     *0       0     2|0  0.0% 0.0%       0  992M 14.0M 0|0 1|0   205b   60.4k    1 Jan 29 18:07:31.277
    *0    *0     *0     *0       0     2|0  0.0% 0.0%       0  992M 14.0M 0|0 1|0   158b   46.4k    1 Jan 29 18:07:32.276
    *0    *0     *0     *0       0     2|0  0.0% 0.0%       0  992M 14.0M 0|0 1|0   158b   46.4k    1 Jan 29 18:07:33.276
    *0    *0     *0     *0       0     1|0  0.0% 0.0%       0  992M 14.0M 0|0 1|0   157b   46.3k    1 Jan 29 18:07:34.277


Step 3 – Install dependencies for compiling.

# yum install gcc openssl-devel plesk-php70-devel
# yum install gcc openssl-devel plesk-php55-devel


Use PECL to install PHP library - for php 7.0.

# /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


Use PECL to install PHP library - for php 5.5.

# /opt/plesk/php/5.5/bin/pecl config-set php_prefix /opt/plesk/php/5.5/bin/
PHP Warning:  PHP Startup: ssh2: Unable to initialize module
Module compiled with module API=20131226
PHP    compiled with module API=20121212
These options need to match
 in Unknown on line 0
config-set succeeded


# /opt/plesk/php/5.5/bin/pecl install mongodb
Build process completed successfully
Installing '/opt/plesk/php/5.6/lib64/php/modules/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.3.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongodb.so" to php.ini


Step 4 – Enable mongodb
Insert the following in /opt/plesk/php/7.0/etc/php.d/mongodb.ini [note: the file may not yet exist]

# vim /opt/plesk/php/7.0/etc/php.d/mongodb.ini
extension=mongodb.so

Now we can find the mongodb extention at info.php page
# service httpd restart



Step 5 – Verifying Startup

# mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
>


Basic syntax of use DATABASE statement is as follows
To create a database with name <mydb>.
> use mydb
switched to db mydb


To check your currently selected database, use the command db
> db
mydb


If you want to check your databases list, use the command show dbs.
> show dbs
admin  0.000GB
mydb   0.000GB
local  0.000GB
>


Reff link:
https://websavers.ca/installing-mongodb-php-plesk-servers
https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-centos-7
https://www.tutorialspoint.com/mongodb/mongodb_create_database.htm


 

This article was:  
Report an issue
Article ID: 989
Last updated: 08 Jul, 2021
Revision: 12
Views: 1792
Comments: 0
Tags