Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
CouchDB and PHP Web Development Beginner's Guide
CouchDB and PHP Web Development Beginner's Guide

CouchDB and PHP Web Development Beginner's Guide:

eBook
$25.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

CouchDB and PHP Web Development Beginner's Guide

Chapter 2. Setting up your Development Environment

In this chapter, we will set up your computer so that you can develop web applications using PHP and CouchDB. There are a lot of technologies that come into play when developing web applications, so we'll need to make sure that our systems are configured properly before we start writing the code.

In this chapter, we will:

  • Discuss your operating system and how to install the necessary components

  • Learn about the tools needed to develop PHP and CouchDB applications

  • Configure our web development environment

  • Learn about Homebrew and install CouchDB

  • Use Homebrew to install Git for version control

  • Confirm that you can make a request to CouchDB

Are you ready? Good! Let's get started by talking about operating systems and the role they play in setting up your development environment.

Operating systems

This book will focus primarily on the Mac OS X Operating System (10.5 and later). While it's possible to develop applications with PHP and CouchDB on any operating...

Operating systems


This book will focus primarily on the Mac OS X Operating System (10.5 and later). While it's possible to develop applications with PHP and CouchDB on any operating system, I will be restricting most of my discussions to Mac OS X for simplicity and brevity. If you're using a Mac, you can skip ahead to the next section, titled Setting up your web development environment on Mac OS X.

If you're running Windows or Linux, don't worry! I'll give you some setup tips to get you started, and then you can take it from there. Again, it's worth noting that the command line statements that I use in this book are meant for use on a Mac OS. With that in mind, things such as navigating to your working directory, the location of files, and many more may not work as described.

Windows

If you're running Windows, there are a few easy steps you need to follow to get your machine up and running.

Installing Apache and PHP

You can simplify the setup of your Apache and PHP environment by using WAMP...

Setting up your web development environment on Mac OS X


In this section, we will go step-by-step and ensure that our development environment is set up correctly. From here on out, I'm assuming you are using a machine that is running Mac OS X without any special modifications to Apache or PHP. If you've done a lot of customization to your development environment, then you probably already know how to configure your machine so that everything works properly.

Now that I've bored you to death with disclaimers, let's get things rolling! The first part of our journey is to meet an application that we will spend a lot of our time with: Terminal.

Terminal

Terminal is a built-in command line utility for Mac OS X. Using the command line can be a bit of a strange experience when you are just getting started but is extremely powerful once it's mastered. If the basic commands, such as cd, ls, and mkdir look like gibberish to you, then you might want to do some quick research on the UNIX command line....

Time for action — using Terminal to show hidden files


Now that we have Terminal up and running, let's get familiar with it by running a quick command that exposes all of the hidden files on your computer. Whether you know it or not, there are a variety of files that are hidden, and they will need to be visible in order for us to complete the setup of our development environment.

  1. 1. Start by opening Terminal.

  2. 2. Type in the following command to allow the Finder to show hidden files, press Enter when you are ready:

    defaults write com.apple.finder AppleShowAllFiles TRUE
    
    
  3. 3. In order to see the files, you will need to restart the Finder, type the following command, and press Enter:

    killall Finder
    
    

What just happened?

We just used Terminal to run a special command that configured Finder to show the hidden files and then ran another command to restart the Finder. It's not important for you to remember these commands or fully understand what they mean; you probably will never have to type this again...

Time for action — opening your web browser


We are going to access the Apache service on our machine by opening a web browser, and navigating to Apache's URL.

  1. 1. Open your web browser.

  2. 2. Type http://localhost into the address bar, and hit Enter.

  3. 3. Your browser will display the following message to you:

What just happened?

We used the web browser to access Apache, and in return, it showed us a quick verification that everything was hooked up correctly. Our computer knew that we were trying to access our local Apache service because of the URL http://localhost. The URL http://localhost actually maps to the address http://127.0.0.1:80, which is the address and port of the Apache service. You will see 127.0.0.1 come up again when we discuss CouchDB.

PHP

PHP is in the title of this book, so you know it will play a big part in the development process. PHP is already installed on your machine, so you have nothing to install. Let's just double check that you can access PHP by using Terminal.

Time for action — checking your PHP version


We are going to check that PHP is working on your computer by accessing it with Terminal.

  1. 1. Open Terminal.

  2. 2. Run the following command for PHP to return its version:

    php -v
    
    
  3. 3. Terminal will respond with something similar to the following:

What just happened?

We used Terminal to ensure that we had PHP running correctly on our machine. Not only did we check to make sure that PHP was accessible, but we also asked for its version. Your version may differ slightly from mine, but it only matters that your version is PHP 5.3 or higher.

Note

If your version is lower than PHP 5.3 or you were unable to get PHP to respond, you can install or upgrade by looking at PHP's manual: http://php.net/manual/en/install.macosx.php.

Time for action — making sure that Apache can connect to PHP


In order to create a web application, Apache needs to be able to run the PHP code. So, we are going to check that Apache can access PHP.

  1. 1. Use Finder to navigate to the following folder: /etc/apache2.

  2. 2. Open the file named httpd.conf in your text editor.

  3. 3. Look through the file, and find the following line (it should be around line 116):

    #LoadModule php5_module libexec/apache2/libphp5.so
    
    
  4. 4. Remove the hash (#) symbol that is in front of this string to uncomment this line of the config file. It's possible that your configuration file may already have this uncommented. If it does, then you don't have to change anything. Regardless, the end result should look as follows:

    LoadModule php5_module libexec/apache2/libphp5.so
    
    
  5. 5. Open Terminal.

  6. 6. Restart Apache by running the following command:

    sudo apachectl restart
    
    

What just happened?

We opened Apache's main configuration file, httpd.conf, and uncommented a line so that Apache can load...

Time for action — creating a quick info page


We are going to double-check that Apache can render PHP scripts by quickly creating a phpinfo page that will display a wide array of data about your configuration.

  1. 1. Open your text editor.

  2. 2. Create a new file that contains the following code:

    <?php phpinfo(); ?>
    
  3. 3. Save the file with the name, info.php, and save that file in the following location: /Library/WebServer/Documents/info.php.

  4. 4. Open your browser.

  5. 5. Navigate your browser to http://localhost/info.php.

  6. 6. Your browser will display the following page:

What just happened?

We used our text editor to create a file called info.php that contained a special PHP function called phpinfo. We saved the info.php file into the folder: /Library/Webserver/Documents. This folder is the default location (in Mac OS X only) for all of the files that your Apache service will display. When your browser hit the info.php page, the phpinfo looked at your PHP installation and returned an HTML file with details...

Time for action — further configuration of Apache


mod_rewrite will allow us to rewrite the requested URLs on the fly, which will help us build an application with clean URLs. The rewriting itself is handled in another Apache configuration file called .htaccess, which we will touch on in Chapter 4, Starting Your Application. In the following section, we'll configure Apache, so that mod_rewrite is enabled.

  1. 1. Use Finder to navigate to the following folder: /etc/apache2.

  2. 2. Locate and open a file named httpd.conf in your text editor.

  3. 3. Look through the file, and find this line (it should be line 114):

    #LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    
    
  4. 4. Uncomment the line by removing the hash (#) symbol. It's possible that your system is already configured to enable mod_rewrite. Regardless, make sure it matches the following code:

    LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    
    
  5. 5. Look through the file, and find this chunk of code (it should go from line 178-183):

    <Directory...

Time for action — installing Homebrew


We are going to use Terminal to download Homebrew and install it onto our computer.

  1. 1. Open Terminal.

  2. 2. Type the following commands into Terminal, pressing Enter after each line:

    sudo mkdir -p /usr/local
    sudo chown -R $USER /usr/local
    curl -Lf http://github.com/mxcl/homebrew/tarball/master | tar xz -- strip 1 -C/usr/local
    
    
  3. 3. Terminal will respond with a progress bar and show you how the installation process went. When the installation is complete, you will receive a success message, and you will have control of the Terminal again.

What just happened?

We added the directory /usr/local, which is where Homebrew will save all of its files. Then we made sure that the folder was owned by us (the current user). We then installed Homebrew using a cURL statement to grab the repository from Github (I'll cover cURL later in this chapter; we are going to use it quite a bit). After grabbing the repository, it was unzipped, using the command line function tar, and...

Time for action — installing CouchDB


Now that we have Homebrew installed, we are finally ready to install CouchDB.

Note

Please note that before Homebrew installs CouchDB, it will install all of its dependencies, which include such things as: Erlang, Spidermonkey, ICU, and so on. This section might take up to 10-15 minutes to complete, because they are being compiled locally on your machine. Don't worry if it seems like it's taking too long; this is normal.

We are going to install CouchDB using Homebrew.

  1. 1. Open Terminal

  2. 2. Run the following command:

    brew install couchdb -v
    
    
  3. 3. Terminal will respond with a lot of text over the next couple of minutes. You will see it grab each dependency and then install it. At the very end, you will receive a success message.

What just happened?

We just installed CouchDB from the source and downloaded all of its dependencies. After installation, Homebrew put everything in the right folders and configured everything we need to use CouchDB.

Checking that our setup is complete


We just accomplished a lot in the past few pages. We've set up our web development environment and installed CouchDB. Now, let's double check that we can run and access CouchDB.

Starting CouchDB

CouchDB is easy to manage. It operates as a service that we can start and stop by using our command line. Let's start CouchDB with a command line statement.

  1. 1. Open Terminal.

  2. 2. Run the following command:

    couchdb -b
    
    
  3. 3. Terminal will reply with the following:

    Apache CouchDB has started, time to relax.
    
    

Great! Now that we have started CouchDB as a background process, it will sit in the background and handle requests until we shut it off.

Time for action — checking that CouchDB is running


We are going to attempt to hit the CouchDB service on our machine by using the command line utility cURL (we'll spell it curl from here on out for the sake of simplicity) that allows you to make raw HTTP requests. curl is our main method of communication with CouchDB. Let's start with a curl statement to talk to CouchDB.

  1. 1. Open Terminal.

  2. 2. Run the following statement to create a request that will hit CouchDB:

    curl http://127.0.0.1:5984/
    
    
  3. 3. Terminal will reply with the following:

    {"couchdb":"Welcome","version":"1.0.2"}
    
    

What just happened?

We just used curl to communicate with the CouchDB service by issuing a GET request. By default, curl will assume that we're trying to issue a GET request unless we tell it otherwise. We issued our curl statement to http://127.0.0.1:5984. Breaking this resource down into pieces, http://127.0.0.1 is the IP of our local computer, and 5984 is the port that CouchDB runs on by default.

Running CouchDB as a background...

Installing version control


Version control systems allow developers to track code changes, merge other developers' code, and to roll back any inadvertent errors. Version control systems are a must on a project with several developers but can also be a lifesaver for single developer projects. Think of it as a safety net — if you accidentally do something you didn't want to, then source control is there to protect you. There are several options when it comes to version control, but in this book, we will use Git.

Git

Git (http://git-scm.com/) has become one of the more popular and widely adopted version control systems because of its distributed nature and ease-of-use. The only thing easier than actually using Git is installing it. We will use Homebrew to install Git, just as we did with CouchDB.

Time for action — installing and configuring Git


Get ready! We are going to install Git onto our computer using Homebrew.

  1. 1. Open Terminal.

  2. 2. Run the following command to install Git using Homebrew:

    brew install git
    
    
  3. 3. Terminal will download and install Git for you in just a matter of moments. It will then respond with a success message telling you that Git has been installed.

  4. 4. After Git has been installed, you need to configure it so that it knows who you are when you commit changes to data. Run the following commands to identify yourself and make sure to fill in your own information where I've put Your Name and your_email@domain.com:

    git config global user.name "Your Name"
    git config global user.email your_email@domain.com
    
    

What just happened?

We just installed Git from the source using Homebrew. We then configured Git to use our name and e-mail address. These settings will make sure that any changes that are committed to source control from this machine are identified.

Did you have any problems?


We're all done with confi guring our system! In a perfect world, everything would be installed without any issues, but it's enti rely possible that something didn't install perfectly. If it seems like something isn't working right, or you think you may have made some typos along the way, I have a script that you can run that will help you get back on track. This command can be executed locally by calling a fi le I have on github. All you have to do is run the following command in Terminal, and it will run all of the necessary code for this chapter:

sh <(curl -s https://raw.github.com/timjuravich/environment-setup/master/ configure.sh)

This script will do all of the work that has been menti oned in this secti on, and it's safe to run as many ti mes as you want. I could have given you this one command and fi nished up the chapter pages ago, but this chapter was integral in teaching you how to use the tools and uti liti es that we will use in the coming chapters...

Summary


Let's do a quick recap of everything we've covered in this chapter:

  • We became familiar with Terminal and used it to show hidden fi les

  • We installed a text editor for us to use in development

  • We learned how to confi gure Apache and how to interact with it through the command line

  • We learned how to create simple PHP fi les and placed them in the correct locati on so that Apache could display them

  • We learned how to install Homebrew, and then we used it to install CouchDB and Git

  • We checked to make sure that CouchDB was up and running

In the next chapter, we'll get more familiar with CouchDB and explore how to use it in the creati on of our web applicati on.

Left arrow icon Right arrow icon

Key benefits

  • 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

Description

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.

Who is this book 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.

What you will learn

  • 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
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 22, 2012
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781849513586
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Jun 22, 2012
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781849513586
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 141.97
PHP and MongoDB Web Development Beginner's Guide
$48.99
CouchDB and PHP Web Development Beginner's Guide
$48.99
Responsive Web Design with HTML5 and CSS3
$43.99
Total $ 141.97 Stars icon

Table of Contents

10 Chapters
Introduction to CouchDB Chevron down icon Chevron up icon
Setting up your Development Environment Chevron down icon Chevron up icon
Getting Started with CouchDB and Futon Chevron down icon Chevron up icon
Starting your Application Chevron down icon Chevron up icon
Starting your Application
What we'll build in this book
Bones
Project setup
Time for action — creating the directories for Verge
Time for action — initializing a Git repository
Implementing basic routing
Time for action — creating our first file: index.php
Time for action — creating the .htaccess file
Time for action — hooking up our application to Bones
Time for action — creating the class structure of Bones
Time for action — creating functions to access the route on Bones creation
Time for action — creating the register function to match routes
Time for action — creating a get function in our Bones class
Time for action — creating routes for us to test against Bones
Handling layouts and views
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
Time for action — rendering views inside of our routes
Time for action — creating views
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
Adding support for complex routing
Adding support for public files
Time for action — altering .htaccess to support public files
Time for action — creating a stylesheet for the application
Publishing your code to GitHub
Get complete code from GitHub
Summary
Connecting your Application to CouchDB Chevron down icon Chevron up icon
Modeling Users Chevron down icon Chevron up icon
User Profiles and Modeling Posts Chevron down icon Chevron up icon
Using Design Documents for Views and Validation Chevron down icon Chevron up icon
Adding Bells and Whistles to your Application Chevron down icon Chevron up icon
Deploying your Application Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(6 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Feb 15, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I found this book to be a very useful tool. For anyone considering using CouchDB and PHP this is the place to start.
Amazon Verified review Amazon
Thomas Hunter II Sep 22, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
When I first picked up this book, I was expecting a boring, text-book approach to code examples for PHP talking with CouchDB. Boy was I wrong. What I found was a book that has you build a complete working application. And by complete, I mean you'll add the Twitter Bootstrap framework and it will be sexy. You'll do things the hard way, and refactor with an easier method. You'll be building a PHP framework with controllers and views. You'll be integrating a third party library for communicating with CouchDB which follows a similar simplistic approach as the framework. You'll also be keeping track of everything in GIT and committing to GitHub. These are all very important things for any application developer to know, and this book will get you into some good habits.The book starts off with an introduction to general NoSQL concepts (schema-less, fast), as well as the history of database systems. It then gets into the history of CouchDB itself. Nothing in there was too surprising, however the author did put a larger emphasis on the lack of ACID compliance than I have seen elsewhere (which means data isn't 100% guaranteed). This is a great thing to point out; it prevents CouchDB from being a fit for many projects (such as financial) however perfect for other projects (high traffic logging applications) and the risk and reward gradient for every application in-between.The author also guides the reader through the complete OS X setup process for getting Apache started, configuring it to work with PHP, getting the homebrew package manager working and subsequently CouchDB installed, running, and persisting between restarts. This means the beginning programmer can take on building this application without any prior knowledge of PHP development. I thought this was a great touch, it is probably the biggest thing holding back people from programming.Overall, this book does a great job explaining REST and the HTTP verbs, how those translate into their CRUD counterparts, how JSON is a great data language to be sent over the wire. Early on we use command line cURL for interacting with the CouchDB server, a slightly tedius method. I absolutely LOVE that the author had us run through cURL requests in the command line BEFORE sending us to the web-based GUI administration app, Futon. This puts a huge emphasis on exactly what kind of data is sent over the wire, something most MySQL developers, for example, will never know.In the third chapter of the book, the author has us dive into securing our CouchDB installation. This is an important topic that could have been otherwise omitted, since it isn't necessary to get an application up and running. By default, CouchDB is insecure, and many a developer may not ever realize this until something bad happens. By calling it out early on, the code doesn't need a large refactor later on to bolt-on authentication.The book has us building a simple PHP framework, named Bones by the author. Of course, we could have skipped building this framework and simply used raw PHP scripts (e.g. having .php extensions in your address bar). This would have been a bit easier for the reader to handle, and wouldn't have required the configuration of mod_rewrite in apache.conf. However, by using this framework, the reader is more likely to explore different frameworks down the road, instead of taking a simpler route. There is a small risk though that the user won't fully understand how Apache maps URI requests to the filesystem. Overall though, by having pretty URLs the completed application looks and feels like more of a solid accomplishment, bringing confidence to the reader.Another thing worth mentioning about the Bones framework is that it makes heavy use of PHPs Anonymous Functions. I personally love this method, as it feels a lot like the Node.js Express framework. PHP didn't get support for Anonymous Functions until version 5.3, which did come out a few years ago and is largely the standard. As a PHP beginner, by learning recent features of the languages, they may be more likely to grok the language than users learning from antiquated tutorials. The framework is currently hosted on GitHub, but it appears largely dead, not having been updated in a year.The author also guides the reader step-by-step through creating a GitHub account, something that can be a little scary to beginners. I used to teach a PHP meetup regularly, and getting an account setup was one of the hardest things to do (it would require an entire session). Creating an SSH key, and doing other configurations on the command line can be daunting, but it really is necessary. So many great projects are hosted on GitHub and the sooner a developer can get in the club the better. After each big milestone, the author has us committing our changes and pushing to GitHub. This is an excellent habit to get into and the author puts a good emphasis on it.When it gets time to have PHP begin communicating with CouchDB, the author has us do so using the cURL library built in to PHP. While cURL is incredibly powerful, it is very difficult for beginners to use. It is also overly verbose. It is generally not appreciated by the PHP crowd and there are many libraries (such as Requests for PHP) built to encapsulate the difficulty with a clean, Object Oriented interface. Luckily for us, the author was using cURL to show us one way of doing things (e.g. the hard way) before switching to a better solution. He soon has us install a library specifically meant for working with CouchDB called Sag, which follows the same beginner-friendly, simple methodology as the Bones framework. He also guides us through refactoring our existing code.The Bones framework soon gets an upgrade as we add a PHP autoloader to load Sag (and later the rest of our classes). The author really does a great job of "sneaking" in a lot good practices like this. Some other nice things that sneak their way in are using Gravatar for displaying users avatars, and using simple jQuery calls for making DELETE requests and fading out newly deleted items. There is also an emphasis on code refactoring and removing redundant code, and the reason we do so is explained nicely.Of course, the application we've bene building so far is not the prettiest (Times New Roman is everyones enemy after all). Thankfully, we soon add support for the Twitter Bootstrap framework. This allows us to quickly get a good looking website up with minimal HTML boilerplate code. Throughout the book we display code in the browser using normal text, then spruce it up with markup to follow Bootstrap methodologies.A lot of PHP developers start by using MySQL as their Database System. To help make the transition to a NoSQL database system easier for those developers, the author often compares a schema-less CouchDB document to an equivalent MySQL tables and relationships. The two approaches to building database management systems are quite different, so this is a helpful comparison.At the end of the book, we take out application and deploy it to some cloud services. The author has us go through the process of setting up a PHP Fog hosting account, as well as a Cloudant CouchDB hosting account, and of course getting the two to communicate. Both of these services offer free accounts, so this doesn't hold back the user. The account setup pages have screenshots for us to follow along and we are told how to get the PHP application to connect to the remote CouchDB instance. We also take our local CouchDB and have it replicate to the remote server, a nice feature which didn't have to make the cut for a beginners book.One thing that I didn't quite understand is why we used the CouchDB _users database instead of rolling our own. It could be that I'm not as familiar with CouchDB as I should be, but it seems like an application specific way would be better than a database specific method. CouchDB uses salted SHA1 password encryption, which we've seen a lot of negative press around over the past year or so. By rolling our own encryption we could have used a more secure encryption such as bcrypt.Another thing I wasn't a fan of was enabling hidden files in Finder. Personally, I would have had the users use the `ls` command in terminal, and mention that there are hidden files that aren't normally shown in Finder. For editing the config files, we could have used the `mate` command provided with Textmate (the text editor the author suggests). By using the command line more it might have made the reader a little more comfortable with it. Thankfully the author does provide a command to disable hidden files once we're done.Overall, CouchDB and PHP Web Development Beginner's Guide is an amazing book for any beginner looking to get into building PHP applications to persist data using CouchDB. There are many good practices sprinkled into the pages within. Anyone running a computer with OS X can follow along, even if they have no prior experience with programming or databases. The verbose code explanations do a great job explaining what the author is having us build. If you are interested in either of these technologies I highly recommend picking up this book.
Amazon Verified review Amazon
Brent Eyler Jun 25, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The author does a terrific job complementing the learning with actual coding to reinforce what I'm reading. Really enjoying it and recommend for anyone seeking to learn CouchDB with PHP
Amazon Verified review Amazon
Dave Poon Sep 25, 2012
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Recently I have been researching about NoSQL, I was looking for a NoSQL database to add more capability to one of my web applications. And I heard something good about CouchDB, I went to the CouchDB official website, I had a quick read at the documentation, however, there're not much tutorials and books about CouchDB and PHP until this book CouchDB and PHP Web Development Beginner's Guide has been published. I found this book is a great resource for learning how the CouchDB and PHP work for web development.The hands-on tutorial writing style that make complicated concept easier to understand, we just need to follow every step, we will discover and learn more through each step. The great thing is not just follow the steps, the author also explain "What Just Happened" for each step that have done. This make me easier to understand the code better, not like some books, we just follow and put the code, run it, it's work, and no explanation about what just happened about the example codes.One of the best parts that I really like is the author teaches you to create a PHP MVC framework called "Bones framework" with CouchDB database, this book teach you how to build a best practices PHP and CouchDB web application from scratch. The author also inform us to use Git (version control system) to commit your code once you have done the changes to your code. This is a great practice to use version control system to keep track of your source code while developing our application. I am really impressed with details like this, it's not just teach you one thing, and forget the others, the author also teach you good programming practice when building a PHP and CouchDB web application.This is the beginner's guide series of the book, however, this book is not easy for beginner to understand. You need or recommend to have experience in object oriented PHP programming, and understand what MVC Model-View-Controller design pattern is, and also have experience using command line for basic system operations.
Amazon Verified review Amazon
Raistrick Jul 27, 2012
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I like the way this book is written. Software books are always nice when you can be taken on a journey through learning (provided you have the time) and this book takes time to introduce you to lots of techniques and tools that will make CouchDB development easier and more organised. For someone wanting to swap an SQL database for a NoSQL database, whilst keeping the server-side programming consistent with previous methods, then this book is great. I'm looking to do this so that the site and data management can be kept separate and take some of the load off the CouchDB developer. However, at the rate that these technologies are changing, along with the errors you are likely to encounter developing anything in CouchDB, you'll find the IRC channel and stackoverflow far more use.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
Modal Close icon
Modal Close icon