- Paperback: 304 pages
- Publisher: Packt Publishing Limited (June 22, 2012)
- Language: English
- ISBN-10: 1849513589
- ISBN-13: 978-1849513586
- Product Dimensions: 7.5 x 0.7 x 9.2 inches
- Shipping Weight: 458 g
- Average Customer Review: Be the first to review this item
CouchDB and PHP Web Development Beginner's Guide Paperback – 22 June 2012
|New from||Used from|
Amazon Global Store US
About the Author
Tim Juravich has architected and led development teams through a variety of projects in PHP, Ruby, and .NET. After gaining experience at several fortune 500 companies, Tim discovered entrepreneurship and founded three of his own startups. When not at work, Tim actively mentors engineers, contributes to open source projects, and works on a variety of side projects. I would like to thank my loving parents, my older...but smaller brother Jon, and my wife Leigha. Without Leigha's support and love through our first year of marriage, this book, and much more would not have been possible. I would also like to thank my clients and colleagues whom have provided invaluable opportunities for me to shape my career, my life, and my perspective on technology.
No customer reviews
|5 star (0%)||0%|
|4 star (0%)||0%|
|3 star (0%)||0%|
|2 star (0%)||0%|
|1 star (0%)||0%|
Review this product
Most helpful customer reviews on Amazon.com
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.
You are shown how to use CouchDB and PHP to create and add capabilities to a simple, Twitter-like social network called "Verge." This example application "will allow users to sign up, log in, and create posts," the author states. His focus, in the book, is on helping you develop and hone skills by discovering "the ins and outs of building a simple but powerful website using CouchDB and PHP."
The book offers many how-to steps and explanatory details. And it is organized into 10 well-defined chapters. One of its key strengths is its structure and use of focused headings. For example, when it is time to do something at your computer, there is a "Time for action" heading, such as: "Time for action - creating new databases in CouchDB."
The step-by-step procedures that you then must perform are written clearly and clearly numbered. And you get more than just a brief description or illustration of what is supposed to happen. The writer also follows up with summary paragraphs labeled "What Just Happened?" These describe the purposes of the steps you just performed and what they achieved. At the end of each chapter, there is another helpful feature: a summary of key points covered.
CouchDB and PHP Web Development Beginner's Guide is well written and, in my view, follows a classic teaching model that often is very effective: "Tell them what you are going to tell them, tell them, and then tell them what you just told them."
The second chapter includes instructions for installing Apache, PHP, Git (for version control), and CouchDB on Windows, Linux and Mac OS X machines. The one disappointment for me is that the author restricts most of his discussions to the Mac OS X operating system (10.5 and later), and he uses Mac OS command line statements "for simplicity and brevity." This means Windows and Linux users have to do some command-line translations and work with files that may be in different locations than the book describes.
If you are not experienced at using using Windows or Linux machines at the command line, you likely should get more command-line experience first or find a willing mentor who knows both Mac OS X and Windows or Linux, before you tackle this book.
But if you are considering ways to create web applications and have some solid computing experience, particularly with Mac OS X, this book can get you started and up to speed with CouchDB and PHP.