[Exploration] IBM Bluemix with PHP and MySQL

IBM Bluemix is a good platform if you need a fast testing and deploying in the cloud without going through the trouble setting up a proper cloud virtual machine like EC2.

Attended one of the recent workshop organised by IBM and University of Wollongong, I was trying to create a sample testing app using PHP and MySQL, but PHP keep failing to connect to MySQL.

Short answer

Create a file called .bp-config/options.json.

    "PHP_EXTENSIONS": ["mysqli"]

Long answer

PHP and MySQL(ClearDB) is not connecting well because for some reasons PHP runtime is not part of the choose able runtime, known as community buildpack on Bluemix. Meaning there is no sample codes or boilerplates on Bluemix. For some other reason, PHP buildpack does not by default supports mysqli (because obvious “nobody use php and mysql”, lol). So, if you want PHP and MySQL on Bluemix.

1. Create a PHP runtime by using the community PHP buildpack.

2. Add the service ClearDB (MySQL) to PHP app.

3. Add Git repository to Dev Ops (aka jazz hub), allows you to edit the code.

4. Edit the code, add


5. Input the above option so that mysqli is included.

6. In your index.php add the following and echo something

$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error){
echo "Something wrong"
} else {
echo "Hello world"

7. Build and Deploy!


The worst thing, failing at mysqli results in a blank page, absolutely nothing to help you to debug (you can using cf command line, but why!). The error message is shown only if php connects to mysql but wrong credential is supplied.

A few hours was spent to get a proper solution to this. Therefore, I am not totally sure how reliable Bluemix as a solution is if you are using PHP and MySQL. I can’t comment on other runtime such as Java, Node.js, Ruby as I haven’t got the time to try them out. However, the integration of git repo and deploy pipeline is amazingly good, Dev Ops deploys to Bluemix automatically once a change is committed and pushed, after some settings.

It doesn’t seems to me that Bluemix is any easier then Amazon EC2.

Either way, happy doing a lot of things before doing anything.

[Reference: Cloud Foundry / PHP Buildpack and Stack Overflow – your best friend]