MongoDB Tutorial 4: Introduction

From The Uniform Server Wiki
Revision as of 13:28, 1 August 2010 by Ric (talk | contribs) (New page: {{Nav MongoDB Tutorial 4}} '''''MongoDB''''' == Introduction == This tutorial covers a production MongoDB plugin for 6-Carbo. As a starting point is uses the plugin covered in [[MongoDB Tu...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 

MongoDB Production Plugin
UniServer 6-Carbo.

MongoDB

Introduction

This tutorial covers a production MongoDB plugin for 6-Carbo. As a starting point is uses the plugin covered in tutorial 2 and the standalone version covered in tutorial 3. Non-authentication components are replaced with their authentication counterparts as covered in the initial plugin design tutorial.

With this structure in place additional functionally is added.

Top

Downloads

We require a working server and plugin to this we will add components from the standalone version covered in tutorial 3.

Downloads and install

  • Create a new folder z_mongo
  1. Download Uniform Server 6-Carbo and save to this foldr.
  2. Extract by double clicking on file
  • Download plugin mongo_plugin_v1_0.exe
  1. Save to folder z_mongo\UniServer
  2. To extract Double click mongo_plugin_v1_0.exe
  • Create two new folders:
  1. z_mongo\temp
  2. z_mongo\zz_temp
  • # Download mongo_pro_standalone_v1_0.exe
  1. Save to z_mongo\zz_temp
  2. To extract Double click mongo_pro_standalone_v1_0.exe

Save original application

This containks correct path information and strt servers code

  • Navigate to z_mongo\UniServer\unicon\tray_menu_2
  • Cut and paste these files to folder z_mongo\temp
    1. mongo_db.php
    2. mongo_db_inc.php
    3. Run_mongo_db.bat

Copy over standalone components

  • Navigate to folder z_mongo\zz_temp\mongodb_1\control
  • Copy following files to folder z_mongo\UniServer\unicon\tray_menu_2
    1. mongo_db.php
    2. mongo_db_inc.php
    3. window_create_database.inc.php
    4. window_delete_user.inc.php
    5. window_drop_database.inc.php
    6. window_port_pass.inc.php
  • Navigate to folder z_mongo\zz_temp\mongodb_1\bin
  • Copy following files to folder z_mongo\UniServer\usr\local\mongo\bin
    1. config_auth.ini
    2. mongo_name_password
  • Navigate to folder z_mongo\zz_temp\mongodb_1\data
  • Copy folder mongodb to folder z_mongo\UniServer\usr\local\mongo\data (allow overwrite)

For download details see MongoDB Introduction (Main Start page)

Top

Update mongo_db_inc.php

Edit file z_mongo\UniServer\unicon\tray_menu_2\mongo_db_inc.php

Replace this section:

$path_array      = explode("\\mongodb_1",getcwd());          // Split at folder usr
$mongo_base      = $path_array[0];                           // find drive letter and any sub-folders 
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base);   // Replace \ with /

//=== FOLDERS ===
define("MONGO_BIN",   "$mongo_base_f/mongodb_1/bin");        // Binaries for MongoDB

//=== FILES ===
define("INFO_TXT",           "$mongo_base_f/mongodb_1/control/read_me.txt"); // Information file
define("NO_NAG_TXT",         "$mongo_base_f/mongodb_1/control/no_nag.txt");  // Dummy file
define("CONFIG_NO_AUTH_F",   "$mongo_base_f/mongodb_1/bin/config_no_auth.ini"); 
define("UNISERV_EXE",        "$mongo_base_f/mongodb_1/bin/uniserv.exe"); // Utility 
define("UNISERV_EXE_B",      $mongo_base.'\mongodb_1\bin\uniserv.exe');  // Utility 
define("MON_PSKILL_EXE",     "$mongo_base_f/mongodb_1/bin/pskill.exe");  // Utility 

define("CONFIG_AUTH_F",      MONGO_BIN."/config_auth.ini"); 
define("NAME_PWD_F",         MONGO_BIN."/mongo_name_password"); 
define("CMD_DUMMY_TXT",      MONGO_BIN."/cmd_dummy.txt"); // Temp command fie

With:


$path_array      = explode("\\UniServer",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                         // find drive letter and any sub-folders 
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /

//=== FOLDERS ===
define("MONGO_BIN",   "$mongo_base_f/UniServer/usr/local/mongo/bin");  // Binaries for MongoDB
define("MONGO_PHP",   "$mongo_base_f/UniServer/usr/local/php");        // PHP 

//=== FILES ===
define("INFO_TXT",        "$mongo_base_f/UniServer/usr/local/mongo/us_info/read_me.txt");   // Information file
define("NO_NAG_TXT",      "$mongo_base_f/UniServer/usr/local/mongo/us_info/no_nag.txt");    // Dummy file
define("INSTALLED_TXT",   "$mongo_base_f/UniServer/usr/local/mongo/us_info/installed.txt"); // Dummy file

define("PHP_INI_1",       MONGO_PHP."/php.ini");                    //php main configuration 
define("PHP_INI_2",       MONGO_PHP."/php.ini_delvelopment_nano");   //php dev configuration 
define("PHP_INI_3",       MONGO_PHP."/php.ini_production_nano");    //php pro configuration 

define("CONFIG_NO_AUTH_F",   MONGO_BIN."/config_no_auth.ini"); 
define("UNISERV_EXE",        MONGO_BIN."/uniserv.exe"); // Utility 
define("UNISERV_EXE_B",      $mongo_base.'\UniServer\usr\local\mongo\bin\uniserv.exe');  // Utility 
define("MON_PSKILL_EXE",     MONGO_BIN."/pskill.exe");  // Utility 

define("CONFIG_AUTH_F",      MONGO_BIN."/config_auth.ini"); 
define("NAME_PWD_F",         MONGO_BIN."/mongo_name_password"); 
define("CMD_DUMMY_TXT",      MONGO_BIN."/cmd_dummy.txt"); // Temp command fie

define("PHPMOADMIN_PAGE", "$mongo_base_f/UniServer/home/admin/www/phpMoAdmin/moadmin.php");         //phpMoAdmin page 
define("REDIRECT_PAGE",   "$mongo_base_f/UniServer/home/admin/www/phpMoAdmin/mongo_redirect.html"); //Redirect to above fie 

All paths are now reference to ubiform server

Top

Add the following function

//=== Config Mongo ============================================================
function config_mongo(){

  $str = 'extension=php_mongo.dll'; // String to find

   $file = file_get_contents(PHP_INI_1); // Read file
   if(!strpos($file, $str)) {            // Check for string
     $fh = fopen(PHP_INI_1, 'a');        // Not found 
     fwrite($fh, $str."\n");             // Add it to file
     fclose($fh);                        // Close file pointer
   }

   $file = file_get_contents(PHP_INI_2);
   if(!strpos($file, $str)) {
     $fh = fopen(PHP_INI_2, 'a');
     fwrite($fh, $str."\n");
     fclose($fh);
   }

   $file = file_get_contents(PHP_INI_3);
   if(!strpos($file, $str)) {
     $fh = fopen(PHP_INI_3, 'a');
     fwrite($fh, $str."\n");
   }

}
//======================================================== END Coonfig Mongo ===

Top

Update mongo_db.php

Edit file z_mongo\UniServer\unicon\tray_menu_2\mongo_db.php

We need to tap into Uniform Server add the follwing to the includes section

include_once "../main/includes/config.inc.php";     // US Control
include_once "../main/includes/functions.php";      // US Control

We want to force path rewrites. Just below include section add the following

//== Checked servers moved
run_location_tracker();   // Have servers moved if moved
                          // update configuration accordingly

If this is a first install configure PHP to install dll ad the follow below the above

//== Configure server to run monoDB 
if(!file_exists(INSTALLED_TXT)){  // File not found 
  config_mongo();                 // Update PHP ini files
 
  //== Create installed file 
  $conf[] = "Php configured\n";
  $conf[] = "php_cli configured\n";

  $str1 = implode($conf);                 // Convert array to string
  file_put_contents(INSTALLED_TXT,$str1); // Save string to file
}


Top

Summary

With the above modifications we now have a working MongoDB plugin.

Compared to mongo_plugin_v1_0 it lacks some functionality, no Apache control and no phpMoAdmin support.

Next page covers adding Apache support.

Top