CouchDB and PHP Web Development Beginner's Guide


CouchDB and PHP Web Development Beginner's Guide
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$22.95
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$67.94
save 6%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Build and deploy a flexible Social Networking application using PHP and leveraging key features of CouchDB to do the heavy lifting
  • Explore the features and functionality of CouchDB, by taking a deep look into Documents, Views, Replication, and much more.
  • Conceptualize a lightweight PHP framework from scratch and write code that can easily port to other frameworks

Book Details

Language : English
Paperback : 304 pages [ 235mm x 191mm ]
Release Date : June 2012
ISBN : 1849513589
ISBN 13 : 9781849513586
Author(s) : Tim Juravich
Topics and Technologies : All Books, Web Development, Beginner's Guides, Open Source, PHP, Web Development

Table of Contents

Preface
Chapter 1: Introduction to CouchDB
Chapter 2: Setting up your Development Environment
Chapter 3: Getting Started with CouchDB and Futon
Chapter 4: Starting your Application
Chapter 5: Connecting your Application to CouchDB
Chapter 6: Modeling Users
Chapter 7: User Profiles and Modeling Posts
Chapter 8: Using Design Documents for Views and Validation
Chapter 9: Adding Bells and Whistles to your Application
Chapter 10: Deploying your Application
Bonus Chapter
Pop Quiz Answers
Index
  • Chapter 1: Introduction to CouchDB
    • The NoSQL database evolution
      • What makes NoSQL different
        • Classification of NoSQL databases
        • CAP theorem
        • ACID
        • So what does all of that mean?
    • Introduction to CouchDB
      • The history of CouchDB
      • Defining CouchDB
    • Summary
    • Chapter 2: Setting up your Development Environment
      • Operating systems
        • Windows
          • Installing Apache and PHP
          • Installing Git
          • Installing CouchDB
        • Linux
          • Installing Apache and PHP
          • Installing Git
          • Installing CouchDB
      • Setting up your web development environment on Mac OS X
        • Terminal
      • Time for action – using Terminal to show hidden files
        • Text editor
        • Apache
        • Web browser
      • Time for action – opening your web browser
        • PHP
      • Time for action – checking your PHP version
      • Time for action – making sure that Apache can connect to PHP
      • Time for action – creating a quick info page
        • Fine tuning Apache
      • Time for action – further configuration of Apache
        • Our web development setup is complete!
        • Installing CouchDB
        • Homebrew
      • Time for action – installing Homebrew
      • Time for action – installing CouchDB
      • Checking that our setup is complete
        • Starting CouchDB
      • Time for action – checking that CouchDB is running
        • Running CouchDB as a background process
      • Installing version control
        • Git
      • Time for action – installing and configuring Git
      • Did you have any problems?
      • Summary
      • Chapter 3: Getting Started with CouchDB and Futon
        • What is CouchDB?
          • Database server
          • Documents
            • Example of a CouchDB document
            • JSON format
            • Key-value storage
            • Reserved fields
          • RESTful JSON API
        • Time for action – getting a list of all databases in CouchDB
        • Time for action – creating new databases in CouchDB
        • Time for action – deleting a database In CouchDB
        • Time for action – creating a CouchDB document
        • Futon
        • Time for action – updating a document in Futon
        • Time for action – creating a document in Futon
        • Security
        • Time for action – taking CouchDB out of Admin Party
        • Time for action – anonymously accessing the _users database
        • Time for action – securing the _users database
        • Time for action – checking to make sure the database is secure
        • Time for action – accessing a database with security enabled
        • Summary
        • Chapter 4: Starting your Application
          • What we'll build in this book
          • Bones
          • Project setup
          • Time for action – creating the directories for Verge
            • Source control with Git
          • Time for action – initializing a Git repository
          • Implementing basic routing
          • Time for action – creating our first file: index.php
            • .htaccess files
          • Time for action – creating the .htaccess file
            • Hacking together URLs
            • Creating the skeleton of Bones
          • Time for action – hooking up our application to Bones
            • Using Bones to handle requests
          • Time for action – creating the class structure of Bones
            • Accessing the route
        • Time for action – creating functions to access the route on Bones creation
          • Matching URLs
        • Time for action – creating the register function to match routes
          • Calling the register function from our application
        • Time for action – creating a get function in our Bones class
          • Adding routes to our application
        • Time for action – creating routes for us to test against Bones
          • Testing it out!
          • Adding changes to Git
        • Handling layouts and views
          • Using Bones to support views and layouts
        • Time for action – using constants to get the location of the working directory
        • Time for action – allowing Bones to store variables and the content path
        • Time for action – allowing our application to display a view by calling it in index.php
        • Time for action – creating a simple layout file
          • Adding views to our application
        • Time for action – rendering views inside of our routes
        • Time for action – creating views
          • Adding changes to Git
        • Adding support for other HTTP methods
        • Time for action – retrieving the HTTP method used in a request
        • Time for action – altering the register to support different methods
        • Time for action – adding simple but powerful helpers to Bones
          • Using a form to test our HTTP method support
          • Testing it out!
          • Adding changes to Git
        • Adding support for complex routing
          • Handling complex routes
          • Accessing route variables
          • Adding more complex routes to index.php
          • Testing it out!
          • Adding changes to Git
        • Adding support for public files
        • Time for action – altering .htaccess to support public files
        • Time for action – creating a stylesheet for the application
          • Adding changes to Git
        • Publishing your code to GitHub
        • Get complete code from GitHub
        • Summary
          • Chapter 5: Connecting your Application to CouchDB
            • Before we get started
            • Time for action – creating a database for Verge with curl
            • Diving in head first
              • Adding logic to our signup script
            • Time for action – adding an e-mail field to the signup form
              • Using curl calls to post data to CouchDB
          • Time for action – creating a standard object to encode to JSON
            • Committing it to Git
          • Time for action – creating a CouchDB document with PHP and curl
            • Committing it to Git
          • Is this technique good enough?
          • Available CouchDB libraries
          • Sag
            • Downloading and setting up Sag
          • Time for action – using Git to install Sag
            • Adding Sag to Bones
          • Time for action – adding Sag to Bones
            • Simplifying our code with Sag
          • Time for action – creating a document with Sag
            • Adding more structure
          • Time for action – including the classes directory
            • Working with classes
          • Time for action – creating a Base object
          • Time for action – creating a User object
          • Time for action – plugging the User object in
            • Testing it out
            • Committing it to Git
          • Wrapping up
          • Summary
            • Chapter 6: Modeling Users
              • Before we get started
                • Cleaning up our interface by installing Bootstrap
              • Time for action – installing Bootstrap locally
              • Time for action – including Bootstrap and adjusting our layout to work with it
              • Time for action – sprucing up the home page
                • Moving all user files into the user folder
              • Time for action – organizing our user views
              • Designing our user documents
                • How CouchDB looks at basic user documents
                • Adding more fields to the user document
                  • Discussing options for adding these fields
                  • Adding support for the additional fields
              • Time for action – adding the fields to support the user documents
              • The signup process
                • A little administrator setup
                • Updating the interface
                • Quick and dirty signup
              • Time for action – handling simple user signup
                • SHA-1
                  • Testing the signup process again
                • Refactoring the signup process
              • Time for action – cleaning up the signup process
              • Exception handling and resolving errors
                • Deciphering error logs
              • Time for action – examining Apache's log
              • Time for action: Examine CouchDB's log
                • Catching errors
              • Time for action – handling document update conflicts using SagCouchException
                • Showing alerts
              • Time for action – showing alerts
              • User authentication
                • Setting up for the login form
                • Logging in and logging out
              • Time for action – adding functionality for users to log in
              • Time for action – adding functionality for users to log out
                • Handling the current user
              • Time for action – handling the current user
              • Summary
              • Chapter 7: User Profiles and Modeling Posts
                • User profile
                  • Finding a user with routes
                • Time for action – getting single user documents
                • Time for action – creating a route for user profiles
                • Time for action – creating the user profile
                  • Testing it out
                  • Adding your changes to Git
                • Fixing some problems
                  • Finding errors
              • Time for action – examining Apache's log
                • Handling 500 errors
              • Time for action – handling 500 errors with Bones
              • Time for action – handling exceptions
                • Testing our exception handler
              • Showing 404 errors
                • 404 if user isn't found
              • Time for action: handling 404 errors with Bones
                • Showing 404 errors for unknown users
                • Hooking up 404 all around the site
              • Time for action – handling 404 errors with Bones
                • Testing it out
              • Giving users a link to their profile
              • Creating a better profile with Bootstrap
              • Time for action – checking whether a user is currently logged in
                • Cleaning up the profile's design
                • Let's check out our new profile
                • Adding your changes to Git
              • Posts
                • Modeling Posts
                  • How to model posts in MySQL
                  • How to model posts in CouchDB
              • Creating posts
              • Time for action – making a function to handle Post creation
              • Time for action – making a form to enable Post creation
              • Time for action – creating a route and handling the creation of the Post
                • Test it out
                • Adding your changes to Git
              • Wrapping up
              • Summary
                • Time for action – querying the posts_by_user view
                  • Using the view in our application
                • Time for action – adding support to get_posts_by_user in the post class
                • Time for action – adding posts to the user profile
                  • Reduce functions
                • Time for action – creating the reduce function in Futon
                • Time for action – adding support to our application to consume the reduce function
                  • More with MapReduce
                • Validation
                • Time for action – adding support for $_rev to our classes
                • Time for action – adding support to delete posts in our application
                  • CouchDB's support for validation
                • Time for action – adding a validate function to ensure that only creators can update or delete their documents
                • Time for action – hiding the delete buttons when not on the current user's profile
                • Wrapping up
                  • Want more examples?
                  • Working with design documents in Futon is too hard!
                • Summary
                  • Chapter 9: Adding Bells and Whistles to your Application
                    • Adding jQuery to our project
                      • Installing jQuery
                    • Time for action – adding jQuery to our project
                    • Time for action – creating master.js and connecting Boostrap's JavaScript files
                    • Using jQuery to improve our site
                      • Fixing our delete post action to actually use HTTP delete
                    • Time for action – improving our user experience by using AJAX to delete posts
                      • Updating our route to use the DELETE HTTP method
                      • Let's test it out!
                  • Adding simple pagination using jQuery
                  • Time for action – taking posts out of profile.php and putting them in their own partial view
                    • Adding backend support for pagination
                  • Time for action – adjusting our get_posts_by_user function to skip and limit posts
                    • Let's test it out!
                  • Time for action – refactoring our code so it's not redundant
                  • Time for action – adding frontend support for pagination
                  • Time for action – fixing our delete post function to work with pagination
                    • Testing our complete pagination system
                  • Using Gravatars
                  • Time for action – adding Gravatars to our application
                    • Testing our Gravatars
                    • Adding everything to Git
                  • Summary
                    • Chapter 10: Deploying your Application
                      • Before we get started
                        • Application hosting
                        • CouchDB hosting
                      • Database hosting with Cloudant
                        • Getting started with Cloudant
                        • Creating a _users database
                        • Creating a verge database
                        • Using Futon on Cloudant
                        • Configuring permissions
                      • Configuring our project
                      • Time for action – creating a configuration class
                      • Time for action – adding our configuration file to Bones
                        • Adding changes to Git
                      • Application hosting with PHP Fog
                        • Setting up a PHP Fog account
                        • Creating environment variables
                        • Deploying to PHP Fog
                          • Adding our SSH key to PHP Fog
                          • Connecting to PHP Fog's Git repository
                          • Deploy to PHP Fog
                      • Replicating local data to production
                      • Time for action – replicating our local _users database to Cloudant
                      • What's next?
                        • Scaling your application
                        • Next steps
                      • Summary
                      • Bonus Chapter
                        • You can download the Bonus Chapter from http://www.packtpub.com/sites/default/files/downloads/Replicating_your_Data.pdf.
                        • Pop Quiz Answers
                          • Chapter 2, Setting up your Development Environment
                          • Chapter 3, Getting Started with CouchDB and Futon

                          Tim Juravich

                          Tim Juravich is an experienced product, program, and technology leader that has spent nearly the past decade leading teams through a variety of projects in PHP, Ruby, and .NET. After gaining experience at several Fortune 500 companies, Tim discovered entrepreneurship, founded three of his own startups, and has helped dozens of other startups open their doors. Tim currently serves as the Director of Program Management for Thinktiv, a venture accelerator.
                          Sorry, we don't have any reviews for this title yet.

                          Code Downloads

                          Download the code and support files for this book.


                          Submit Errata

                          Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                          Errata

                          - 4 submitted: last submission 29 Apr 2013

                          Errata type: Code| Page number: 85 | Errata date: 29-4-2013

                           

                          PHP code refers to "view_content); ?>"
                          
                          should be
                          
                          "content); ?>"

                           

                           

                          Errata type: Code| Page number: 73 | Errata date: 26-4-2013

                           

                          "This variable is set by the function get_route()," should say "This variable  
                          is set by the function get_method(),"
                          and
                          "The get_route() function uses an array called $_SERVER" should say "The  
                          get_method() function uses an array called $_SERVER"

                           

                           

                          Errata type: Code| Page number: 27 | Errata date:26-4-2013

                           

                          The line of code:
                          
                          curl -Lf http://github.com/mxcl/homebrew/tarball/master | tar xz -- strip 1  
                          -C/usr/local
                          
                          does not work on some versions of Mac OSX (produces error related to  
                          "strip").
                          
                          The line should be:
                          curl -Lf http://github.com/mxcl/homebrew/tarball/master | tar xz --  
                          strip-components 1 -C/usr/local
                          

                           

                           

                          Errata type: Code| Page number: 31 | Errata date: 26-4-2013

                           

                          The following two lines need to have -- in front of the word 'global' or else  
                          you get a git error ("error: key does not contain a section: global").
                          
                          git config global user.name "Your Name"
                          git config global user.email your_email@domain.com
                          
                          should be
                          
                          git config --global user.name "Your Name"
                          git config --global user.email your_email@domain.com
                          

                           

                           

                          Sample chapters

                          You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                          Frequently bought together

                          CouchDB and PHP Web Development Beginner's Guide +    Google App Engine Java and GWT Application Development =
                          50% Off
                          the second eBook
                          Price for both: $37.50

                          Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                          What you will learn from this book

                          • Set up a web development environment from scratch
                          • Dive into CouchDB and learn how it looks at databases, documents, design documents, and views
                          • Conceptualize and create a simple PHP framework from scratch that will interact directly with CouchDB
                          • Create the ability for users to sign up, log in, and reset their password through our application using CouchDB
                          • Allow users to create posts and leverage design documents, views, and lists to do the heavy lifting
                          • Learn how to add some of the bells and whistles commonly used by modern social networks
                          • Add security and deploy your application to production
                          • Learn how to use CouchDB to replicate your database

                          In Detail

                          CouchDB is a NoSQL database which is making waves in the development world. It’s the tool of choice for many PHP developers so they need to understand the robust features of CouchDB and the tools that are available to them.

                          CouchDB and PHP Web Development Beginner’s Guide will teach you the basics and fundamentals of using CouchDB within a project. You will learn how to build an application from beginning to end, learning the difference between the “quick way” to do things, and the “right way” by looking through a variety of code examples and real world scenarios.

                          You will start with a walkthrough of setting up a sound development environment and then learn to create a variety of documents manually and programmatically. You will also learn how to manage their source control with Git and keep track of their progress. With each new concept, such as adding users and posts to your application, the author will take you through code step-by-step and explain how to use CouchDB’s robust features. Finally, you will learn how to easily deploy your application and how to use simple replication to scale your application.

                          Approach

                          Each chapter follows the creation of a social networking application with step-by-step instructions. This means that you will have easily created a complete, working application by the end of the book.

                          Who this book is for

                          This book is for beginner and intermediate PHP developers interested in using CouchDB development in their projects. Advanced PHP developers will appreciate the familiarity of the PHP architecture and can easily learn how to incorporate CouchDB into their existing development experiences.

                          Code Download and Errata
                          Packt Anytime, Anywhere
                          Register Books
                          Print Upgrades
                          eBook Downloads
                          Video Support
                          Contact Us
                          Awards Voting Nominations Previous Winners
                          Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                          Resources
                          Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software