如何在Bitnami WAMP(windows)上安装mongoDB以便与symfony 3一起使用?

时间:2016-09-08 18:32:14

标签: windows mongodb symfony bitnami

如何在Bitnami WAMP(windows)上安装mongoDB以便与symfony 3一起使用?

Windows 10,x64。

php PHP 5.6.20(cli)(建于2016年3月31日14:56:44)。

我尝试过从1.1.1到1.1.8的mongodb版本 来自http://pecl.php.net/package/mongodb

我设法在Windows上下载并安装mongodb。但我无法将它与WAMP和symfony一起使用。

这个问题有点改变,因为我设法开始工作php_mongodb.dll。

composer.json

"require": {
    "mongodb/mongodb" : "dev-master", 
    "doctrine/mongodb": "dev-master",
    "alcaeus/mongo-php-adapter": "^1.0.0",
    "doctrine/mongodb-odm": "~1.1",
    "doctrine/mongodb-odm-bundle": "~3.0",

目前的问题是

c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\patmonS1>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - alcaeus/mongo-php-adapter 1.0.0 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.1 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.2 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.3 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.4 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.5 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - mongodb/mongodb 1.0.2 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.1 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - Installation request for alcaeus/mongo-php-adapter ^1.0.0 -> satisfiable by alcaeus/mongo-php-adapter[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5].

  To enable extensions, verify that they are enabled in those .ini files:
    - C:\Bitnami\wampstack-5.6.20-0\php\php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

之前的问题是,如果我安装php_mongodb,我无法运行php,如下所述。我通过安装Bitnami MEAN堆栈和copyong php_mongo.dll和php_mongodb.dll到Bitnami WAMP php / exy文件夹解决了这个问题。

1)WINDOWS安装(工作) - 1)从以下位置下载msi: https://www.mongodb.com/download-center#community https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/ 记住DB的安装位置 - 和 将此路径添加到系统变量:C:\ Program Files \ MongoDB \ Server \ 3.2 \ bin

运行cmd:mongod

为数据库文件创建一个文件夹,例如在C:\ Bitnami \ mongodb上 并运行命令 c:\ Users \ gintare> mongod --dbpath C:\ Bitnami \ mongodb

这将在文件夹中创建一个数据库。

2)Symfony安装(不起作用) composer.json

"require": {
    "doctrine/mongodb": "dev-master",
    "alcaeus/mongo-php-adapter": "^1.0.0",
    "doctrine/mongodb-odm": "~1.1",
    "doctrine/mongodb-odm-bundle": "~3.0",

2a)我按照步骤操作 http://php.net/manual/en/mongo.installation.php#mongo.installation.windows 已下载mongodb.dll 1.8.8 http://pecl.php.net/package/mongodb 解压缩为: C:\Bitnami\wampstack-5.6.20-0\php\ext\php_mongodb-1.1.8-5.6-ts-vc11-x64 我尝试了线程安全和不安全的版本。两者都给出了同样的错误。

并将文件php_mongodb.dll复制到C:\Bitnami\wampstack-5.6.20-0\php\ext 并通过添加php.ini更正extension=php_mongodb.dll。从Bitnami重新启动Apache。

然而我收到错误Unable to load dynamic library

c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\patmonS1>php 
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:/Bitnami/wampstack-5.6.20-0/php/ext\php_mongodb.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0

2b)如果我尝试使用pecl安装,我收到错误invalid package

:\Bitnami\wampstack-5.6.20-0\php\ext>pecl install mongodb
downloading mongodb-1.1.8.tgz ...
Starting to download mongodb-1.1.8.tgz (806,900 bytes)
.................................................................................................................................................................done: 806,900 bytes
could not extract the package.xml file from "C:\Bitnami\wampstack-5.6.20-0\php\pear\download\mongodb-1.1.8.tgz"
Download of "pecl/mongodb" succeeded, but it is not a valid package archive
Error: cannot download "pecl/mongodb"
Download failed
install failed

2c)如果我尝试使用composer安装mongoDB,我收到错误doctrine/mongodb dev-master requires ext-mongo ^1.5

c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\patmonS1>composer update

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:/Bitnami/wampstack-5.6.20-0/php/ext\php_mongodb.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for doctrine/mongodb dev-master -> satisfiable by doctrine/mongodb[dev-master].
    - doctrine/mongodb dev-master requires ext-mongo ^1.5 -> the requested PHP extension mongo is missing from your system.
  Problem 2
    - alcaeus/mongo-php-adapter 1.0.0 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.1 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.2 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.3 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.4 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - alcaeus/mongo-php-adapter 1.0.5 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].
    - mongodb/mongodb 1.0.2 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.1 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - Installation request for alcaeus/mongo-php-adapter ^1.0.0 -> satisfiable by alcaeus/mongo-php-adapter[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5].

  To enable extensions, verify that they are enabled in those .ini files:
    - C:\Bitnami\wampstack-5.6.20-0\php\php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\patmonS1>

        "doctrine/mongodb-odm": "~1.1",

1 个答案:

答案 0 :(得分:0)

我将从结论开始:安装Bitnami meanstack,学习javascript,node.js,react.js,Docher容器等等。忘记Symfony和php。

A)在Windows上安装和设置mongodb

1)从https://www.mongodb.com/download-center#community https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

下载msi

2)记住安装DB的位置 - 并将此路径添加到系统变量:C:\ Program Files \ MongoDB \ Server \ 3.2 \ bin

3)来自http://pecl.php.net/package/mongodb的mongodb绑定v1.1.1到1.1.8的官方mongodb.dll php对我不起作用。因此我安装了Bitnami MEAN堆栈并将php_mongo.dll和php_mongodb.dll复制到Bitnami WAMP php / ext文件夹。

4)比配置的网络和服务:

https://blog.ajduke.in/2013/04/10/install-setup-and-start-mongodb-on-windows/

https://mkmanu.wordpress.com/2014/07/30/solution-trouble-in-listening-port-27017-after-installing-mongodb-on-windows-7-64bit/

C:\WINDOWS\system32>netsh
netsh>advfirewall firewall
netsh advfirewall firewall> add rule name="Open mongod port 27017" dir=in action=allow protocol=tCP localport=27017
Ok.

netsh advfirewall firewall>add rule name="Allowing mongod" dir=in action=allow program="C:\mongodb\bin\mongod.exe"
Ok.

netsh advfirewall firewall>add rule name="Allowing mongos" dir=in action=allow program="C:\mongodb\bin\mongos.exe"
Ok.

netsh advfirewall firewall> ctrl+c  (quit this netsh and advfirewall firewall)

现在安装服务:

C:\WINDOWS\system32>mongod -f c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\patmonS1\mongodb.conf  --install --serviceName mongodb27017 --serviceDisplayName "mongodb server instance on port 27017" --serviceDescription "mongoDB server instance running on 27017"

使用--remove,如果要删除它。

启动您刚刚创建的服务(您也可以从服务中执行此操作):

C:\WINDOWS\system32>net start mongodb27017
The mongodb server instance on port 27017 service is starting.
The mongodb server instance on port 27017 service was started successfully.

启动shell:

C:\WINDOWS\system32>mongo
MongoDB shell version: 3.2.9
connecting to: test
>

5)从shell测试数据库

C:\WINDOWS\system32>mongo
MongoDB shell version: 3.2.9
connecting to: test
> for (var i=1; i<=25; i++) db.testData.insert( {x:i} )
WriteResult({ "nInserted" : 1 })
> db.testData.find()
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271925"), "x" : 1 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271926"), "x" : 2 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271927"), "x" : 3 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271928"), "x" : 4 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271929"), "x" : 5 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd827192a"), "x" : 6 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd827192b"), "x" : 7 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd827192c"), "x" : 8 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd827192d"), "x" : 9 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd827192e"), "x" : 10 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd827192f"), "x" : 11 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271930"), "x" : 12 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271931"), "x" : 13 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271932"), "x" : 14 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271933"), "x" : 15 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271934"), "x" : 16 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271935"), "x" : 17 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271936"), "x" : 18 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271937"), "x" : 19 }
{ "_id" : ObjectId("57d3f53b78fbe7dbd8271938"), "x" : 20 }
Type "it" for more
>

6)从index.php

测试数据库
<?php

// http://localhost/index.php
// C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\index.php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
//echo get_include_path();
//phpinfo();

// connect
$m = new MongoClient();

// select a database
$db = $m->comedy;

// select a collection (analogous to a relational database's table)
$collection = $db->cartoons;

// add a record
$document = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
$collection->insert($document);

// add another record, with a different "shape"
$document = array( "title" => "XKCD", "online" => true );
$collection->insert($document);

// find everything in the collection
$cursor = $collection->find();

// iterate through the results
foreach ($cursor as $document) {
    echo $document["title"] . "\n";
}

//List all databases
    $databases = $m->listDBs(); 
    echo ' <br> databases = <pre>';
    print_r($databases);
    $somedb=$m->$databases['databases'][0]['name'];


//List all collections from some database
    $collections =$somedb->listCollections();
    echo '<br> collections = <pre>  ';
    print_r($collections);
    $someCol=$somedb->$collections[0];


//List all documents from some collection  
$cursor = $someCol->find();
echo '<br> documents = <pre>  ';
foreach ( $cursor as $id => $value )
{
    echo "$id: ";
    var_dump( $value );
} 

7)从symfony3项目控制器动作测试mongodb:

C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\patmonS1\src\Pat\monBundle\Controller\DefaultController.php

<?php

namespace Pat\monBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

use \MongoClient;

// http://127.0.0.1:8000/   - url to see the output of this action

/**
 * Default controller.
 *
 * @Route("/")
 */
class DefaultController extends Controller
{
    /**
     * @Route("/")
     */
    public function indexAction()
    {
     //   phpinfo(); - should list mongo information like
     /*   MongoDB Support   enabled
Version     1.6.14
Streams Support     enabled
Supported Authentication Mechanisms
MONGODB-CR  enabled
SCRAM-SHA-1     enabled
MONGODB-X509    disabled
GSSAPI (Kerberos)   enabled
PLAIN 
      */

// connect
$m = new MongoClient();

 //the rest is the same as with index.php above in point 6.

B)symfony3的软件包安装与mongo.db一起使用

C:\ Bitnami \ wampstack-5.6.20-0 \的Apache2 \ htdocs中\符号\ patmonS1 \ composer.json

    "require": {
        "doctrine/mongodb": "dev-master",
        "alcaeus/mongo-php-adapter": "^1.0.0",
        "doctrine/mongodb-odm": "~1.1",
        "doctrine/mongodb-odm-bundle": "~3.0",

为了能够安装所述软件包,你必须检查phpinfo()你使用什么类型的架构(x86或64),你使用的是什么版本的php,以及你的php是否是线程安全的。比从pecl下载相应的mongo.dll https://pecl.php.net/package/mongo/1.6.14/windows ,解压缩并复制到 C:\Bitnami\wampstack-5.6.20-0\php\ext。 在C:\Bitnami\wampstack-5.6.20-0\php\php.ini中添加或取消注释相应的行。它应该是行:

extension=php_mongo.dll
extension=php_mongodb.dll

重启apache。

似乎php_mongo.dll由SYmfony 3软件包使用(过时!)。 php_mongodb.dll可以直接在http://php.net/manual/en/mongo.tutorial.php

中描述的$m = new MongoClient();这样的PHP中使用

如果我尝试从控制器操作或位于$m = new MongoClient();的index.php连接到此C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs的mongodb,它将完美地工作,如下所述。

相关问题