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!

Integrating PHP Web Applications with JCR and Magnolia CMS

I first came across PHPCR through my work with Magnolia CMS, an open source Java CMS. Magnolia CMS uses the Java Content Repository (JSR-283) as its content storage mechanism and PHPCR is a PHP adaptation of that standard. It’s great for storing semi-structured content in a hierarchical format and it also includes support for content versioning and indexing.

The cool thing about PHPCR is that it lets PHP developers interact with content stored in a JCR-compliant content repository using PHP objects and APIs…no Java knowledge needed. This means that you could save data to a JCR repository using a Java application, then read or modify that data using PHP, simplifying data reuse and interoperability between applications running on different platforms.

Read more in my tutorial on integrating PHP applications with Magnolia CMS. It discusses a number of common use cases, including reading and writing content to a JCR repository and integrating a PHP front-end with a Java application via the JCR.

Build and Deploy a Mobile-Friendly Calorie Counter on IBM Bluemix with PHP, MySQL, AngularJS and the Nutritionix API

The Nutritionix API is an online API which lets you access a massive database of nutrition information, covering both generic and branded food items. I came across it recently when looking for something else, and was promptly diverted from my original goal into trying it out.

While playing with it, it occurred to me that this could be the basis of a very neat little application to track calorie consumption. Ideally, it needed to work on a mobile device so that it would be at hand at meal-times, and be simple, interactive and easy to use. After a little thought, I had my requirements and design down, so I went ahead and built it.

Check out the video below to see it in action:

For the user interface, I used jQuery Mobile and AngularJS (something I’ve been itching to play with for a while). On the server, I used Slim, a PHP micro-framework, to connect with the Nutritionix API. The application is deployed on IBM Bluemix, which is also responsible for providing a MySQL service instance for account and meal record storage.

Although I’ve used the PHP/MySQL combination on IBM Bluemix before, this application gave me an opportunity to try something new: email send-outs. If you’re developing locally, or on a system you have administrative privileges for, it’s easy enough to configure a mail server to handle outgoing email traffic, then use PHP’s mail() function to do the deed. On a PaaS service, this isn’t quite as easy…but Bluemix’s SendGrid service provides a viable solution if you’re willing to experiment a bit.

For the full story, read my IBM developerWorks article…and then, don’t forget to try the demo app.

Build and Deploy a REST API on IBM Bluemix with PHP and MySQL

I’ve been experimenting with IBM Bluemix for some time now and a few weeks ago, I decided to try hosting a custom REST API with it. I built the API using Bullet, a PHP micro-framework, then deployed it to Bluemix and connected it with Bluemix’s MySQL service. It worked out pretty well…as you can see by trying this live demo.

In case you’re interested in learning how I went about building this, you can read all about it in this IBM developerWorks article. In this article, I explain how to implement the four basic REST methods using Bullet, then add support for API authentication and multiformat support, and finally deploy the API to Bluemix. Take a look, then download the API source and see what you think!

Configure URL Rewriting for Framework-Based PHP Applications on IBM Bluemix

A few weeks ago, I was introduced to Bluemix, IBM’s new cloud infrastructure platform for developers. With a bunch of pre-configured runtimes for Java, Node.js and Ruby, plus MongoDB, MySQL and various other database services, BlueMix provides a platform for quick app development and deployment.

Bluemix is currently in beta and doesn’t support PHP (yet) but I found a blog post which suggested it was possible using the Zend Server PHP buildpack. However, on trying it, I came across a problem: my Web application (built with Slim Framework) needed URL rewriting for its custom routes to work, but I couldn’t find a way to edit the nginx configuration file included with the Zend Server PHP buildpack. The search for an alternative led me (via Q&A in this thread) to the Cloud Foundry PHP buildpack, which solved my problem.

In case you’re looking to run a PHP application on Bluemix and you need URL rewriting (or other server-level modifications to configuration), here are the steps I followed:

1. Use the application manifest to load the Cloud Foundry PHP buildpack.
The application manifest file manifest.yml tells the Cloud Foundry CLI how to deploy the application, including which buildpack to use. Here’s what I used.


- name: my-slim-php-app
memory: 256M
instances: 1
host: my-slim-php-app

2. Override default buildpack settings with your custom configuration.
The best thing about the Cloud Foundry PHP buildpack is that it lets you override default httpd, nginx and PHP configuration settings with your own. All you need to do is add a .bp-config/ directory to your application’s root, then add an options.json file with buildpack configuration variables.

By default, the buildpack will install Apache as the Web server. To use nginx instead, I made some changes.


  "WEB_SERVER": "nginx"

The buildpack also lets you custom-configure Apache, nginx or PHP, simply by adding your custom configuration files within a httpd/, nginx/ or php/ sub-directory. By combining the URL rewriting instructions in Slim’s documentation with the existing nginx defaults, I generated the following overrides.


        listen @{VCAP_APP_PORT};
        server_name _;

        fastcgi_temp_path @{TMPDIR}/nginx_fastcgi 1 2;
        client_body_temp_path @{TMPDIR}/nginx_client_body 1 2;
        proxy_temp_path @{TMPDIR}/nginx_proxy 1 2;

        real_ip_header x-forwarded-for;
        real_ip_recursive on;

        # ?$args or ?$query_string at the end of the next line
        # tells nginx to forward query arguments
        try_files $uri /index.php?$query_string;


        # Some basic cache-control for static files to be sent to the browser
        location ~* \.(?:ico|css|js|gif|jpeg|jpg|png)$ {
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";

        # Deny hidden files (.htaccess, .htpasswd, .DS_Store).
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;

        # modified from Slim documentation
        # pass *.php to the fastcgi process  
        location ~ .*\.php$ {
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass php_fpm;

3. Push your application code to Bluemix.

shell> cf api
shell> cf login
shell> cf push

That’s pretty much all there is to it. You should now be able to access your Slim routes without any problems. These settings should also work (with minor changes) for other framework-based PHP applications, including those written with BulletPHP, Zend Framework and Agavi.

If you prefer Apache, this thread explains how to set up the necessary URL rewriting rules for Apache. If you don’t have a Bluemix account, you can request one here.

Improve Web Application Security with Zend Framework 2

I’ve been working with Zend Framework 2 for a while now, trying to learn it and map its concepts to those from Zend Framework 1. One of the things that hasn’t changed is the framework’s support for security – it still has a bunch of useful components which let you protect your PHP application from SQL injection, XSS, CSRF, spam, and brute-force password hacking.

You don’t need to be using Zend Framework either – the framework is loosely coupled, so you can use the components on a standalone basis. If you’re not familiar with framework-based development, this gives you all the benefits of components like Zend\InputFilter and Zend\Escaper without the additional overhead and learning curve.

Read more in my IBM developerWorks article on web application security and find out how to harden your application against bad input, XSS vectors, bots and spam. Code examples are included for both framework and standalone usage.