Exploring IBM Bluemix – Part 2: Using PHP

0.00 avg. rating (0% score) - 0 votes

This article in my IBM Bluemix series will show you how to deploy your first PHP application on Bluemix, the next generation cloud app development platform from IBM.

Before continuing you should have already set up your IBM Bluemix free trial account. Refer to my previous article for details.

Creating your PHP application

Now log in to your Bluemix dashboard, select your space and choose to create a new web app. When prompted, select PHP as the application type:

web_templates

Enter a name for your application, a host (e.g. sub-domain) for it, and take note of the trial limitations and cost:

php_create

In the above screenshot, the application will be available at http://hello-php.mybluemix.net once created.

Click on Create to create the app, which will take a while to complete. When done, you should see your application under the list of applications:

app_list_details

That’s it! Now visit your application home page and you should see the default PHP template that comes with Bluemix:

php_default_templates

 

Great isn’t it? Your PHP site is ready in just a few clicks. But, wait a minute, where are all the codes? The answer is simple, click Start Coding on the left menu:

php_start_code

You will be offered two methods to start your actual PHP development:

  • Via Cloud Foundry, known as CF
  • Via Git

To use Cloud Foundry, you will need to download the toolkit from here and install it on your computer. After installation, a file named cf.exe will be present in C:\Program Files (x86)\CloudFoundry (or in C:\Program Files\CloudFoundry if you’re on a 32-bit machine) and you’ll be using this tool to upload and deploy your code. You can also use Git which facilitates the process and supports version control. To pick your option, click on either CF or Git in the right panel:

cf_git

If you choose Git, you will receive an email with instructions on how to set up Git with IBM DevOps to facilitate deployment. As Git is quite straight forward to use, the rest of the article will use CF for demonstration purposes.

Next, click Download Starter Code to download the Bluemix PHP code template for your project, which contains the following files:

php_code_default

The default template has an index.php with some images and css styles. You are free to change any files you wish during development, except for the manifest.yml files which contains the project settings, otherwise your project may not deploy properly:

applications:
- disk_quota: 1024M
buildpack: php_buildpack
host: toughdev-php
name: ToughDev PHP
path: .
domain: mybluemix.net
instances: 1
memory: 128M

For testing purposes, we will be making the following changes to index.php:

echo "Modified by ToughDev!";
...
for ($i=0;$i<100;$i++)
{
	echo "$i "; 

	if ($i%5==0)
		echo "<br/>";
}

Deploy your modified application using the following commands, replacing your username, space name and project name appropriately. You may need to set the PATH variable to point to the cf.exe installation folder for the commands to work.

cf api https://api.ng.bluemix.net
cf login -u [username] -o [username] -s [space_name]
cf push [project_name]

The deployment process should start and finish without issues:

upload_cf

Interestingly there is a reference to Heroku, another cloud application development platform, in the console output of cf.exe.

When done, visit the application home page and you should see the modified PHP code:

php modified

Congrats, you have successfully deployed your first PHP application on Bluemix!

Some thoughts

Things seem great so far – you can deploy your WordPress blog or PHP codes in just a few clicks, literally. But what’s the catch? The first thing I noticed is that the deployment process using Cloud Foundry is quite slow – more than five minutes over a Windows command line on a fast Internet connection – even slower than using a shared hosting FTP. I hope this is just a limitation of cf.exe and things will be faster when using Git with DevOps, although I have not had the time to explore that in details.

The second issue comes when I inspect the PHP environment using phpinfo():

display_errors

Bluemix is using PHP 5.5, which is good enough for most purposes. However, display_errors is set to off, resulting in a blank page if your PHP code has any kind of issues whatsoever. A quick test verifies that this is indeed the case – a missing semicolon and your page will not render at all. I have tried the following workarounds to no avail:

  • using error_reporting(E_ALL) on the top of each page
  • using ini_set(“display_errors”, 1) to override php.ini
  • putting a custom php.ini on the application folder

None of this works and Bluemix refuses to show any PHP errors. There is also a section named Files and Logs on the Bluemix portal which shows the directory structure but otherwise contains no relevant log files (Apache or PHP log files), apart from the deployment log, staging_task.log:

staging_log

Unless there is some configuration setting which I overlooked, this seems to be a major limitation having to test your deployment without knowing the exact error messages. On the contrary, other PHP web hosting providers such as Bluehost offer the ability to change php.ini, either through cPanel or by uploading a custom php.ini file, or even changing the PHP version or preferred execution engine (FastCGI, Apache, mod_php, etc).

Fortunately phpinfo() shows that cURL, MySQL, and other common extensions are supported. I have not yet had the time to verify their functionalities, however.

Another thought that comes to my mind during the experiment is the fair usage policy of Bluemix. After all, is Bluemix Cloud Foundry environment comparable to a shared hosting environment, a VPS, or even dedicated hosting (unlikely)? Are there any hidden limitations such as inode usage limit or CPU throttling other than bandwidth and disk space limit as stated on the website? For one thing, I know most shared hosting environments implement these limitations to prevent abuse, which only come to light once you’ve exceeded them, resulting in your account being banned or even worse, files permanently deleted. Maybe these limitations are somewhere in the terms of use, which I have not yet had the time to have a close look.

For now, the Bluemix dashboard shows you the amount of memory you’re using and the number of running services:

mem_usage

It also shows how much CPU and memory your PHP application is using:

php_usage

By default. you are allowed 128MB of memory and 1GB of disk space usage per a single PHP application. Above screenshot is the statistics (64MB of memory and 212.3MB of space) for my above test application, which certainly seems excessive. Perhaps the space usage count includes other binaries/object files that are produced during the deployment process.

The verdict

Regardless of some of the above limitations, I guess using PHP on Bluemix certainly has its advantages – quick deployment process and service reliability compared with other PHP hosting providers. You at least don’t have to worry about your sites going down and can integrate your PHP code with other services provided by Bluemix at the same time. These possibilities will be explored in my next few articles in this series, which will show you how to use Node.js and Ruby, as well as how to set up a VPS on Bluemix. Stay tuned!

 

 

 

0.00 avg. rating (0% score) - 0 votes
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

One thought on “Exploring IBM Bluemix – Part 2: Using PHP

  • March 6, 2018 at 6:03 pm
    Permalink

    How does Bluemix compares again industry giants like AWS or Google cloud? I have used both on Cloudways PHP web hosting platform and it was really satisfying. The performance and uptime was just what I needed.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>