Search code examples
phpmongodbwampserver

MongoDb PHP driver installation issue on wamp


I have php of version 5.5.12 and wamp version 2.4.9 and PHP Extension Build as API20121212,TS,VC11 . I am using this dll 'php_mongo-1.5.5-5.5-vc11.dll' (renamed to php_mongo) but still when i restart my all services mongo db is not displaying on phpinfo().Any pointer where m i going wrong ?


Solution

  • I have never used MONGO, but I was interested to see if there where problems using it with WAMPServer so I did a quick install to prove it shoud work, and it does.

    Here is a list of what I did, I hope it helps you work out what you may have done wrong.

    First you have to download the Mongo Database manager itself and install it. Download from https://www.mongodb.org/downloads

    Updated Aug 2019: Download from here now

    So you can place the software yourself I would download the ZIP and NOT the .MSI this way you dont get your system messed with by the .msi developer and what they think should be done to your system and you are in complete control.

    Download the 32bit or 64 bit version to match your OS and WampServer(32/64) version you are running.

    Now the Install is just a case of extracting the files from the zip and placing them somewhere on your system. I suggest :-

    Copy the bin folder from the extract to c:\wamp\bin\mongo\mongox.y.z ( x.y.z to match the version of mongo you downloaded).

    Create a data folder under that folder, so c:\wamp\bin\mongo\mongox.y.z\data Create a data folder for your first database under that folder, so \wamp\bin\mongo\mongox.y.z\data\db

    Create a config file for mongo in c:\wamp\bin\mongo\mongox.y.z\mongod.cfg and add as a minimum these parameter :-

    NOTE: these are just params that will get it running, NOT A DEFINITIVE SET OF PARAMETERS!

    systemLog:
      destination: file
      path: "c:/wamp/logs/mongod.log"
      logAppend: true
      timeStampFormat: iso8601-local
    
    net:
      bindIp: 127.0.0.1
      port: 27017
    
    storage:
      dbPath: "c:/wamp/bin/mongo/mongo2.6.6/data"
      directoryPerDB: true
    

    Now if you want to have mongodb running as a service create a command file like so in the C:\wamp\bin\mongo\mongox.y.z folder :-

    Filename = install_service.cmd

    mongod.exe --config "c:\wamp\bin\mongo\mongo2.6.6\mongod.cfg" --install --serviceName wampmongodb --serviceDisplayName wampmongodb
    sc config wampmongodb start= demand
    

    The space between start= and demand is required, not a typo

    For completeness also create an uninstall file :-

    Filename = uninstall_service.cmd

    mongod.exe --remove --serviceName wampmongodb
    

    Now create 2 command files to start and stop your mongodb instance

    Filename = start_mongo.cmd

    net start wampmongodb
    

    Filename = stop_mongo.cmd

    net stop wampmongodb
    

    Now start a command window using (Run as Administrator) and use these command files to install and start your MONGODB Server

    CD \wamp\bin\mongo\mongox.y.z
    #Install MONGO as a service
    install_service
    #Start the service
    start_mongo
    

    Now check the c:\wamp\logs folder and make sure there are no errors reported in the mongod.log file

    While still in the command window, check that mongo is running by trying a few simple commands Use the instructions here http://docs.mongodb.org/manual/tutorial/getting-started/ to prove that it is all working.

    NOW ADD THE PHP Extension

    Download from 'http://pecl.php.net/package/mongo'

    Select the version you want and click the Windows icon with the word DLL beside it, in the 'Downloads' column.

    This will take you to the download page for that version of the MONGO PHP extension.

    You should now select the download link that matches the version of the MONGO extension you want, and the matching (x86) for 32bit WAMPServer installs or (x64) for 64bit WAMPServer installs.

    You must click the 'DLL' link otherwise you will get a unix/linux source code.

    Remember you must match the 32 or 64 bit to the version of WAMPServer you downloaded

    So if you are running Windows 64bit but installed WAMPServer 32bit you need the 32bit version of the MONGO extension.

    Also remember that you need the Thread Safe version (TS) to run with WAMPServer's Apache configuration.

    Extract the zip file, and copy php_mongo.dll to your PHP folder eg C:\wamp\bin\php\phpx.y.z\ext

    Edit your php.ini file to add the new extension. To use Mongo with your web server (Apache) use the wampmanager menus to edit php.ini i.e.

    wampmanager -> PHP -> php.ini
    

    and add this line after all the other extension lines

    extension=php_mongo.dll
    

    To use mongo with scripts run from the command line (PHP CLI) edit C:\wamp\bin\php\phpx.y.z\php.ini and add the extension line again in there.

    Start Wampmanager. Or Restart the Apache service. This should refresh WAMPServers config and pick up the new PHP extension, if not do this when wampmanager is running:-

    wampmanager -> Apache -> Service -> Restart Service
    

    Run localhost by :-

    wampmanager -> localhost
    

    and then click on the phpinfo() link on the homepage.

    You should now see a section entitled 'mongo' with some configuration options listed. If you do the PHP MONGO extension is active.

    IMPORTANT

    If you are running Windows Server 2008 R2 or Windows 7 you may have to install this HotFix to resolve an issue with Memory Mapped Files. Request it from here http://support.microsoft.com/kb/2731284/en-us. You have to ask for it, and then they send you an email telling you where it can be downloaded from.

    The link they gave me was http://hotfixv4.microsoft.com/Windows 7/Windows Server2008 R2 SP1/sp2/Fix405791/7600/free/451412_intl_i386_zip.exe

    However I did not need to install it to get to the stage where MONGO was installed and running simple tests from the command line AND through Apache and PHP.