Free Sample
+ Collection

PHP and MongoDB Web Development Beginner’s Guide

Beginner's Guide
Rubayeet Islam

Combine the power of PHP and MongoDB to build dynamic web 2.0 applications
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781849513623
Paperback292 pages

About This Book

  • Learn to build PHP-powered dynamic web applications using MongoDB as the data backend
  • Handle user sessions, store real-time site analytics, build location-aware web apps, and much more, all using MongoDB and PHP
  • Full of step-by-step instructions and practical examples, along with challenges to test and improve your knowledge

Who This Book Is For

This book assumes that you are experienced in web application development using PHP, HTML, and CSS. Having working knowledge of using a relational database system such as MySQL will help you grasp some of the concepts quicker, but it is not strictly mandatory. No prior knowledge of MongoDB is required.

Table of Contents

Chapter 1: Getting Started with MongoDB
The NoSQL movement
MongoDB A document-based NoSQL database
Downloading, installing, and running MongoDB
Time for action - downloading and running MongoDB on Windows
Time for action - downloading and running MongoDB on Linux
Creating databases, collections, and documents
Time for action - creating databases, collections, and documents
Installing the PHP driver for MongoDB
Time for action - installing PHP driver for MongoDB on Windows
Connecting to the MongoDB server from PHP
Time for action - creating a connection to the MongoDB server from PHP
Chapter 2: Building your First MongoDB Powered Web App
A MongoDB powered blog
Have the MongoDB server running
Inserting documents in MongoDB
Time for action - building the Blog Post Creator
Querying documents in a collection
Time for action - retrieving articles from a database
Doing advanced queries in MongoDB
Time for action - building the Blog Dashboard
Updating documents in MongoDB
Time for action - building the Blog Editor
Deleting documents in MongoDB
Time for action - deleting blog posts
Managing relationships between documents
Time for action - posting comments to blog posts
Chapter 3: Building a Session Manager
Understanding HTTP sessions
Understanding PHP native session handling
Time for action - testing native PHP session handling
Implementing session handling with MongoDB
Time for action - building the SessionManager class
Putting the SessionManager in action
Time for action - putting SessionManager into action
Building the user authentication module
Time for action - building the User class
Creating the login, logout, and user profile page
Time for action - creating the login, logout, and profile page
Using good session practices
Chapter 4: Aggregation Queries
Generating sample data
Time for action - generating sample data
Understanding MapReduce
Performing MapReduce in MongoDB
Time for action - counting the number of articles for each author
Performing MongoDB MapReduce within PHP
Time for action - creating a tag cloud
Performing aggregation using group()
Time for action - calculating the average rating per author
Listing distinct values for a field
Time for action - listing distinct categories of articles
Counting documents with count()
Chapter 5: Web Analytics using MongoDB
Why MongoDB is a good choice as a web analytics backend
Logging with MongoDB
Time for action - logging page visits with MongoDB
Extracting analytics data with MapReduce
Time for action - finding total views and average response time per blog post
Real-time analytics using MongoDB
Time for action - building a real-time page visit counter
Chapter 6: Using MongoDB with Relational Databases
The motivation behind using MongoDB and an RDBMS together
Defining the relational model
Time for action - creating the database in MySQL
Caching aggregation results in MongoDB
Time for action - storing the daily sales history of products in MongoDB
Benefits of caching queries in MongoDB
Using MongoDB for data archiving
Time for action - archiving old sales records in MongoDB
Storing metadata in MongoDB
Time for action - using MongoDB to store customer metadata
Problems with using MongoDB and RDBMS together
Chapter 7: Handling Large Files with GridFS
What is GridFS?
Storing files in GridFS
Time for action - uploading images to GridFS
Serving files from GridFS
Time for action - serving images from GridFS
Reading files in chunks
Time for action - reading images in chunks
When should you not use GridFS
Chapter 8: Building Location-aware Web Applications with MongoDB and PHP
A geolocation primer
Detecting the location of a web page visitor
Time for action - detecting location with W3C API
Geospatial indexing
Time for action - creating geospatial indexes
Performing location queries
Time for action - finding restaurants near your location
Geospatial haystack indexing
Time for action - finding nearby restaurants that serve burgers
Chapter 9: Improving Security and Performance
Enhancing query performance using indexes
Time for action - creating an index on a MongoDB collection
Optimizing queries
Securing MongoDB
Time for action - adding user authentication in MongoDB
Ensuring data durability
Chapter 10: Easy MongoDB Administration with RockMongo and phpMoAdmin
Administering MongoDB with RockMongo
Time for action - installing RockMongo on your computer
Using phpMoAdmin to administer MongoDB
Time for action - installing phpMoAdmin on your computer
RockMongo versus phpMoAdmin

What You Will Learn

  • Get MongoDB up and running on the machine (Windows/Mac/Linux)
  • Build a PHP-powered website with MongoDB as the data storage
  • Handle HTTP sessions with MongoDB
  • Store website analytics data in real time
  • Process large datasets with MapReduce
  • Use MongoDB to supplement your existing relational database– build data archives, cache tiers, store results of expensive SQL queries in MongoDB
  • Build location-aware web applications
  • Optimize MongoDB for better performance and security


In Detail

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.


Read More