Create and Deliver Invoices Online with IBM Bluemix and PHP

At the end of every month, I sit down for a couple of hours to create and send out invoices to my customers. Up until very recently, this involved opening up an invoice template in a word processor, entering the date and invoice number, adding up the hours worked, and calculating the total and any taxes. I’d then export each invoice as a PDF and email it out. As if that wasn’t bad enough, at the end of each accounting year, I had to review a directory full of PDF files to calculate how much I’d earned, if any invoices were unpaid, and how many projects I’d completed.

Sounds tedious? It was.

A few months ago, I decided I needed a better, less annoying approach. I decided to create a Web-based invoice generator, one that would need only the minimum necessary information from me and would take care of everything else (including generation, delivery and reporting). Since the plan was to eventually release it as an open source project for anyone to use and since every firm has its own invoice format, easy customization of the invoices was also a key design factor.

It didn’t take long to come up with a working prototype and go from there to the finished product. The final version of the application asks for basic invoice details (which customer, what was purchased, for how much) and then created a PDF invoice by merging this input with an HTML template. The template is fully customizable (so long as you know HTML, you can add your own logo, fonts, colours and layout) and the final invoice is saved online, sent to the customer via email and can be exported as a PDF file on demand. Oh, and it’s fully mobile-optimized too, so you can bill a customer with just a few keystrokes even if you’re travelling…

Here’s a sample invoice:

To make reporting and management easier, I wrapped a couple of views around the information in the database:

I used a bunch of different tools to create this application:

If you’re looking for a better way to do invoices, try the live demo or fork the code on Github and use it for your own business. If you’re interested in finding out how to deploy or customize the application, read my developerWorks article for the full details.

Build a Mobile Web App for Assisting Stray Dogs

Ever seen an injured stray on the side of the road and wished you could help, but didn’t know who to call? A couple of months ago, I started thinking about how technology could help address this problem. I began to imagine a mobile application which anyone could use to quickly report injured or ill strays to a central database, including photos and GPS locations. This information could then be used by rescue agencies dedicated to stray assistance.

The more I thought about it, the more viable it seemed. After a few experiments, I had the basic user interface ready and a MongoDB database provisioned to receive user reports (with GPS coordinates automatically included). I added an option for users to attach photos from their device cameras to their reports, and hooked it all up to the Google Maps API so that every report could be correlated with a visual map location. A few minutes later, and it was live on Bluemix.

Here’s what the reporting form looks like:
And here’s an example report cross-referenced with Google Map data. This additional information makes it easier to locate the animal being reported.
Try the prototype out, or fork the code on Github and use it for your own neighbourhood or city. If you’re interested in finding out more, read my developerWorks article, which walks you through all the technical details.

Create a Browser-Based PDF Storage and Search Application

Like most people, I send and receive a lot of documents over email, and the vast majority of those are in PDF format. Over the last few months, I’ve been playing with the idea of moving all these documents into a single location and building an application to automatically index them. This would not only make it easier to find a specific one quickly, but also simplify backing things ups.

Fast forward to last week, and I was reading about some of the Watson services in IBM Bluemix. It occurred to me that it would be fairly easy to combine the Watson Document Conversion service with the AlchemyAPI Keyword Extraction service to automatically turn PDFs into text and then extract keywords from them. I could store the keywords in a database and wrap a search interface around it to create a fairly neat little PDF storage/search application.

As it turned out, it worked exactly as I’d thought it would. A few hours of coding and I had the skeleton of a working application. A few more hours to hook it up with a couple of data stores (MongoDB for the keywords, a Swift object store for the actual PDFs) and add a pretty GUI, and my application was live on Bluemix.

The final version lets users select and upload PDF documents from their computer. As each document is uploaded, it is automatically and intelligently scanned for keywords and those keywords are extracted and stored in a database. Users can later search by keyword to quickly identify and download documents relevant to their needs. Needless to say, it’s all mobile-optimized, so you can get to your documents from both your smartphone and your desktop computer.

Here’s an example of what it looks like in action:

Try the prototype out, or fork the code on Github. If you’re interested in finding out more, read my developerWorks article, which walks you through all the technical details.

Build a Notepad Application with PHP, MongoDB, and IBM Bluemix

I’ve been looking for an excuse to play with MongoLab’s DBaaS for a while…so when I had to choose a database for my latest IBM Bluemix application, MongoDB was first on my list. I like the idea of a document-oriented database as an alternative to the traditional RDBMS, and I was keen to try this in a real-world context.

As it turned out, MongoDB’s document-oriented structure was a great fit for my idea of a fast, searchable, color-coded notepad in the cloud. Each “note” is modeled as a document in a MongoDB collection, and full-text searches across the documents in the collection are extremely efficient. Thanks to MongoLab’s browser-based management, it was also very easy to configure and connect the MongoDB database to the PHP application running on Bluemix.


The end result is a low-overhead mobile Web application that lets you store, categorize and search free-form text notes in the cloud. Check it out on Github, or read more in this IBM developerWorks article.

Build a PHP App that Uses GPS Data From an IoT Device

For many people, the Internet of Things is…well, the Next Big Thing. It’s all about using the cloud, real-time data, and new sensor technology to collect, store and analyze information from a wide range of previously-unwired sources: your house, your car, your refrigerator, your pet and so on.

While IoT is certainly very exciting, it’s hard to figure out exactly how to get started building IoT applications…especially if you’re a Web developer without a background in electrical engineering (like me). So I decided to invest a few weekends in learning about IoT and seeing if I could actually get a working IoT application up and running in PHP.

That’s where the Internet of Things Foundation (IoTF) service came in. A hosted cloud service that’s available through IBM Bluemix, IoTF makes it super-easy to aggregate real-time streams for devices and do something useful with them. After a little bit of research, I was able to successfully use it to retrieve GPS coordinates from my Android smartphone and then combine that data with the Google Maps API (and a little bit of PHP glue) to plot my phone’s location on a map in real time.

php-iotIt’s a simple application, but it goes a long way towards demonstrating the potential of IoT applications…and it’s also given me the foundation I need to begin building more complex applications. If this sounds like something you’d like to get in on as well, take a look at my IBM developerWorks article about using IoT with PHP, and also has some code for you to get started with.

Build and Deploy an Investment Tracking Application in the Cloud with IBM Bluemix

Financial data is now more accessible than ever via open APIs. This makes it easy to build Web or mobile applications that let you track your investment portfolio on a minute-by-minute basis (or at least as often as you care to check it). That’s the idea behind my new portfolio tracking application, which lets you create a virtual portfolio of stocks and then shows you the current market value at any given point.

How does it work? It’s mainly driven off the Quandl API, which is free to use and offers access to both open and premium financial databases. The Quandl API supports thousands of datasets, but I’m only using the free WIKI dataset, which is a community-curated list of end-of-day stock prices and dividends for 3,000 US companies.

The application itself is written in PHP using the Silex micro-framework and uses a hosted Cloudant instance for data storage. jQuery Mobile ensures that the interface works well on smartphones, and the entire thing is hosted on Bluemix for maximum scalability. There’s also a little bit of HybridAuth in the mix, just so that every user can create his or her own account in the system using existing Google credentials.

Sounds interesting? Try a demo, check out the source code on Github, or read about how I developed it in this two-part IBM developerWorks article.

Build a Photo Storage Service in the Cloud with PHP and IBM Bluemix

Cloud storage is increasingly popular because it’s cheap and scalable. Amazon Simple Storage Service (Amazon S3) is probably the most well-known, but almost every serious cloud vendor now has a storage offering. Cue my research into IBM Bluemix and its Object Storage service, which lets you attach cloud storage to your Bluemix application.

Bluemix’s Object Storage service is based on OpenStack Swift and follows Swift’s three-tier hierarchy for organizing data: accounts, containers and objects. To try it out, I built a photo storage application hosted on Bluemix and integrated it with the Bluemix Object Storage service. With a little help from the IBM jStart PHP client library, it was easy enough to implement single-user photo upload and storage. And because Bluemix’s Object Storage service supports multiple sub-accounts per service instance, it wasn’t too hard to extend the base application to support multiple users and multiple containers per user.

The final application uses Bootstrap for the user interface, Silex for application flow control, Twig for page templates and HybridAuth for user authentication. You can read the complete article here, get the source code from Github, or try out a live demo.

Debugging PHP Errors on IBM Cloud

I’ve been using IBM Cloud (aka IBM Bluemix) for various projects, but one of the things that often frustrates me is the lack of debug information available. For example, it’s quite common to upload a new PHP application to IBM Cloud and then see a blank page when attempting to access it.

The typical reason for this is that there’s a script error somewhere but the buildpack is configured to hide errors. Normally, the server error logs would let you figure out which script was causing the problem but since IBM Cloud is a PaaS, there’s no server console to log in to and tail log file output.

The best solution here is to tail recent log file output using the command below:

shell> cf logs <app_name>

You can also dump recent log file output using the command below:

shell> cf logs <app_name> --recent

As the image below illustrates, this usually has enough information to help you locate the source of the error, fix it and push a revised build to IBM Cloud.


Build and Deploy an ATM Finder App on Bluemix

Google makes a number of APIs available for free – I’ve previously written about the Google Tasks API and the Google+ API. I recently came across another interesting one – the Google Places API. As the name suggests, the Google Places API lets you retrieve information about shops, businesses, and other establishments by location or keyword. The information returned by the API is quite detailed – it includes place names, place types, coordinates, addresses, opening hours, all coupled with a unique place ID.

While experimenting with it, I thought of one useful application: finding the nearest ATM at any given location. It turned out to be reasonably easy to build, and things for even more interesting when I mashed up the ATM coordinates returned by the Google Places API with a map from the Google Maps API. The end result: a neat little mobile application that uses your current location to find a list of nearby ATMs, then shows you where they are on a map.

This mobile ATM finder is now live on IBM Bluemix. Try it for free from your smartphone, read about how I built it or download the code to see what makes it tick.

Host Your Application in the Cloud with XAMPP and Bitnami

If you’re a developer used to developing and testing applications locally, moving your code to the cloud can be a bit daunting. First, you have to choose a cloud from the numerous options availabe. Then, you need to deal with the nitty-gritties of pricing, provisioning, application deployment, scalability and security. And finally, you need to keep track of server performance, debug application issues and find ways to cost-efficiently improve performance.

Wish you had someone to hold your hand through the process? Read my detailed Apache Friends tutorials, which walk you through the process of hosting a PHP application in the cloud with Bitnami. In these tutorials, I describe how to use the Bitnami LAMP Stack to simply and efficiently create and provision a cloud server, then transfer your PHP application to it and monitor its performance.

The tutorial covers these these popular cloud hosts:

Take a look…you’ll be surprised by how easy it actually is!