Book Image

PHP and MongoDB Web Development Beginner's Guide

Book Image

PHP and MongoDB Web Development Beginner's Guide

Overview of this book

With the rise of Web 2.0, the need for a highly scalable database, capable of storing diverse user-generated content is increasing. MongoDB, an open-source, non-relational database has stepped up to meet this demand and is being used in some of the most popular websites in the world. MongoDB is one of the NoSQL databases which is gaining popularity for developing PHP Web 2.0 applications.PHP and MongoDB Web Development Beginner’s Guide is a fast-paced, hands-on guide to get started with web application development using PHP and MongoDB. The book follows a “Code first, explain later” approach, using practical examples in PHP to demonstrate unique features of MongoDB. It does not overwhelm you with information (or starve you of it), but gives you enough to get a solid practical grasp on the concepts.The book starts by introducing the underlying concepts of MongoDB. Each chapter contains practical examples in PHP that teache specific features of the database.The book teaches you to build a blogging application, handle user sessions and authentication, and perform aggregation with MapReduce. You will learn unique MongoDB features and solve interesting problems like real-time analytics, location-aware web apps etc. You will be guided to use MongoDB alongside MySQL to build a diverse data back-end. With its concise coverage of concepts and numerous practical examples, PHP and MongoDB Web Development Beginner’s Guide is the right choice for the PHP developer to get started with learning MongoDB.
Table of Contents (17 chapters)
PHP and MongoDB Web Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Time for action - downloading and running MongoDB on Windows


We are going to learn how to download, install, and run MongoDB on a computer running on Windows:

  1. 1. Head on over to the downloads page on the MongoDB official website, http://www.mongodb.org/downloads.

  2. 2. Click on the download link for the latest stable release under Windows 32-bit. This will start downloading a ZIP archive:

  3. 3. Once the download is finished, move the ZIP archive to the C:\ drive and extract it. Rename the extracted folder (mongodb-win32-i386-x.y.z where x.y.z is the version number) to mongodb.

  4. 4. Create the folder C:\data\db. Open a CMD prompt window, and enter the following commands:

    C:\> cd \mongodb\bin
    C:\mongodb\bin> mongod
    
  5. 5. Open another CMD prompt window and enter the following commands:

    C:\> cd \mongodb\bin
    C:\mongodb\bin> mongo
    
  6. 6. Type show dbs into the shell and hit Enter.

What just happened?

In steps 1 to 3, we downloaded and extracted a ZIP archive that contains binary files for running MongoDB on Windows, moved and extracted it under the C:\ drive, and renamed the folder to mongodb for convenience. In step 4, we created the data directory (C:\data\db). This is the location where MongoDB will store its data files. In step 5, we execute the C:\mongodb\bin\mongod.exe program in the CMD prompt to launch the MongoDB server; this is the server that hosts multiple databases (you can also do this by double-clicking on the file in Windows Explorer). In step 6, after the server program is booted up, we invoke the C:\mongodb\bin\mongo.exe program to start the mongo interactive shell, which is a command-line interface to the MongoDB server:

C:\mongodb\bin\mongo
MongoDB shell version: 1.8.1
connection to test
type "help" for help
>

Once the shell has started, we issue the command show dbs to list all the pre-loaded databases in the server:

>show dbs
admin (empty)
local (empty)
>

Installing the 64-bit version

The documentation at the MongoDB website recommends that you run the 64-bit version of the system. This is because the 32-bit version cannot store more than 2 gigabytes of data. If you think it is likely that the data in your database will exceed the 2 GB limit, then you should obviously download and install the 64-bit version instead. You will also need an operating system that supports running applications in the 64-bit mode. For the purpose of the practical examples shown in this book, we are just fine with the 32-bit version, you should not worry about that too much.