Realities of open source cloud computing, Part 2: Developing for the cloud

You've probably heard the phrase "Write once, run anywhere." But if you want to write for an application that runs in a cloud, you really have to know what you're doing. Here in Part 2 of this "Realities of open source cloud computing" series, learn how to write an application using PHP to run on the Aptana cloud computing platform. Explore some of the critical design differences between a cloud application and a traditional N-tier application. The concepts are illustrated with a seemingly simple application, using familiar open source technologies, that taps into the strengths of cloud computing.


Michael Galpin (, Software architect, eBay

Michael Galpin has been developing Web applications professionally since 1998. He is a software engineer at eBay in San Jose, CA. He holds a degree in mathematics from the California Institute of Technology.

14 April 2009

Also available in Russian Japanese Vietnamese

About this series

In this three-part "Realities of open source cloud computing" series, learn how to determine if cloud computing can help you and how to plan your cloud computing strategy. Part 1 outlines the benefits of cloud computing, the types of clouds, and the high-level choices in cloud computing platforms. Part 3 covers other parts of the life cycle for an application deployed on the cloud.

In this article, learn to write a simple application using PHP that will run on the Aptana cloud computing platform. Explore the design differences between a cloud application and a traditional N-tier application.

Cloud computing architectures

Tailoring your software to the environment it runs in is critical if you want the software to be stable, perform well, and scale to meet the demand placed upon it. This is an important consideration whether you own the environment your software runs in or if you don't own that environment. As you learned in Part 1, not all clouds are equal. The different types of cloud computing require different considerations. You'll need to distinguish between basic and specialized cloud computing platforms.

Architecture for specialized platforms

Highly specialized platforms are the most intrusive when it comes to architecture. They have many considerations you'll need to address when you design an application that runs on these clouds. Of course, they bring unique benefits that compensate for the restrictions. The Google App Engine is a good example.

When you create an application for the Google App Engine, the only thing you create is the application source code and any static assets (images, for example) that it needs. You have no control over the application server or data access. There's a good reason for this: The App Engine provides highly scalable solutions. However, you need to understand the infrastructure that the App Engine provides. Google provides an API (the Google Query Language) for accessing the App Engine's data store. This is intentionally very similar to SQL, making it easier for you to start using the data store. The data store is not a relational database; it's closer to a simple file system.

Simple access is a little slower than a simple query (find a single object by primary key) to a database. Relational queries, such as table joins, are possible, but they are implemented by multiple sequential queries. They're considerably slower than a join on a relational database, but, as a result, it is much harder to create a query that overwhelms the data store.

To take advantage of data store, it is often advised to de-normalize your data, allowing for related data to be stored together and retrieved together. For example, imagine storing user information where each user can have several phone numbers. This is a classic one-to-many relationship, and would usually be modeled for a database as a user table and a phone number table, where the phone number table contains a foreign key to the user table. You could certainly model it the same way with Google's data store, but it would be more efficient to encapsulate the phone number as part of the user (as a list or an array of phone numbers). A single query to the data store would return everything you need.

The Google App Engine is not the only cloud computing platform that uses this model. One of Amazon's platforms, the SimpleDB, works in an identical fashion. You could run MySQL, Postgres, or any other database on EC2, but SimpleDB is easy to use and provides certain scalability benefits (scaling horizontally is much easier when you essentially do not allow joins). The Ning platform, another specialized platform, also provides a similar access pattern.

You can reap many benefits by using specialized platforms, but there are characteristics you must keep in mind when designing an application that will run on them. It can often be simpler to use a basic cloud computing platform.

Architecture for basic platforms

Basic platforms, such as Amazon EC2 or Joyent Accelerator, give you great freedom to run any software you want on their cloud. There are fewer restrictions to your architecture. If you're architecting for a basic platform, you can approach it almost as if you owned all of the platform yourself. How would you design your application if you were going to run it in your own data center, or on servers leased from a colocation provider? You probably do not need to change the design that much if you want to run the application on a cloud computing platform.

You can run Web applications on basic platforms, just as you would with a specialized platform like the Google App Engine, but you get to use whatever application server or database you want. Of course, the downside is that you need to set up, install, configure, and manage all of this infrastructure. The cloud platform is not going to help you out much.

There is some middle ground out there, too. The Aptana Cloud platform provides a lot of flexibility, as it is layered on top of the Joyent Accelerator. Aptana reduces your work by providing several open source-based infrastructure options to build your application on. It also has great tools for simplifying the deployment process. The key to success is using open source technology choices.

Leveraging open source

With a basic platform, you get to pick your application server, database, etc. So what would you pick? If you were building your own data center, you'd want to use open source technologies. The same applies to a cloud platform. You would pick a Linux® or UNIX® operating system, an Apache Web server with the appropriate module for your programming language of choice, and a MySQL or Postgres database. These are such common choices that you can find some preconfigured options. An even easier option is to use the Aptana Cloud.

Aptana Cloud

The Aptana Cloud layers open source technology on top of the Joyent Accelerator platform. Joyent uses the Xen virtualization technology on top of the OpenSolaris operating system, so the combination of Joyent and the open source technologies used by Aptana is truly a pure, open source platform. Aptana uses the Apache Web server, the Postfix e-mail server, and the MySQL database. It provides Apache plug-ins for PHP and for Jaxer, which is an open source container for using server-side JavaScript. As of this writing, Aptana also offers a private beta for Ruby on Rails on the Aptana Cloud.

Using the Aptana Cloud is very straightforward. Aptana's platform is integrated into its flagship product, the Aptana Studio IDE. Just download the Studio, use it to create your application, deploy your application to the Aptana Cloud. If you have your own tools you prefer for building your application, that will work, too. Simply import it into Aptana Studio and use Studio for deploying the application to the cloud. The following sections look at building and deploying an application to the Aptana Cloud.

Building an application

The sample application in this article uses PHP on the Aptana Cloud. To use Aptana Studio to develop your application, all you need to do is install the PHP plug-in, as shown below.

Figure 1. Install PHP plug-in for Aptana Studio
Install the PHP plug-in for Aptana Studio

Once the plug-in is installed, you can start writing PHP. It is a full IDE, so you can run your PHP application, debug it, etc. It also provides an interface for interacting with a database.

For the sample application, you will create a customized blog. This type of application is well suited for a simple platform, such as the Aptana Cloud. You can start the application with minimal resources and at a low cost. You can increase the resources (vertically scale) as the application grows in popularity. But even a minimal application is "burstable" (it will automatically increase CPU usage to handle bursts in usage). If you need to sustain high numbers of users, you will need multiple servers to horizontally scale, and you'd likely want to use Joyent Accelerator directly to handle a customized architecture.

Since the example application is a blog, you get to take a shortcut. The application is based on the WordPress blogging software. This is a pure PHP application that uses a MySQL database, making it a great fit for the Aptana Cloud. It is open source, so you simply download the code, customize it, and deploy it to your server. In this case, the server is actually the Aptana Cloud.

One of the first tasks for any WordPress application is to configure it by editing the wp-config.php script. This sets up your database access and cookie security. Listing 1 shows a typical file.

Listing 1. Configuring WordPress
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wpadmin');

/** MySQL database password */
define('DB_PASSWORD', 'your_password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/** More stuff omitted. */

There are some important things to note here. If you are developing on your local workstation, you probably have your MySQL database on the same machine. You would set the DB_HOST to localhost. This is the same setting you would use on the Aptana Cloud. The database will run on the same machine as your application server. You do not have to change the code that runs on your workstation when you deploy it to the Aptana Cloud.

One reason WordPress is so popular is that it's extensible. There are several plug-ins available for it. For example, assume that your company doesn't just want a blog to interact with customers. It also wants to use Twitter to let customers know when there is a new blog post. You can use the Twitter Tools plug-in for WordPress for this. It's just a PHP script you download and copy to the wp-content/plugins subdirectory. If this doesn't do exactly what you want, you can modify the code or write your own PHP.

You can also customize the look and feel of WordPress by creating a new theme (a set of PHP scripts, CSS files, and images) and putting the code in the wp-content/themes subdirectory. Once you're done customizing your code, it's time to deploy to the Aptana Cloud.

Deploying to the Aptana Cloud

One of the great benefits of Aptana is its deployment. To deploy, simply choose Aptana > Cloud > Deploy project, as shown below.

Figure 2. Deploying to Aptana Cloud
Deploying to Aptana Cloud

The first time you deploy a project to the Aptana Cloud, you will be prompted for some basic registration information. You can deploy to the Aptana Cloud free for three weeks, so you don't have to enter any payment information at first. Once you've entered the basic information, Aptana will set up your virtual server on the cloud.

Figure 3. Provisioning the Aptana Cloud
Provisioning the Aptana Cloud

After your site has been provisioned and set up, you're ready to deploy your code. Most likely, you won't just copy code from your workstation to the cloud but would want to use source-control management software. Once again, Aptana provides this for you and leverages open source. Aptana uses Subversion and sets up a source-control repository on the cloud. When you're ready to deploy your code, you actually add it to Subversion.

Figure 4. Deploying code — Adding to Subversion
Deploying Code -- Adding to Subversion

Once Aptana has added your code to Subversion and deployed it, you can use its Smart Sync to update any incremental changes you make to the application. Aptana also provides a user interface for adding team members to the application so others can pull the code down from Subversion and collaborate. With multiple people working on an application, it can become unstable. Luckily, Aptana creates a staging site on the cloud, as well as the production site. You can test changes on staging before promoting to production.

Deploying data

Source-control management is great for deploying code to the cloud, but what about data? For WordPress, you would install it locally first, which causes WordPress to insert configuration data into its database. As you add plug-ins, themes, and other configuration tweaks, more data will be written to the database. This is typical for data-driven applications. Some configuration or seed data is needed. Fortunately, this is easy to deploy to the cloud with Aptana. Simply take the dump of your database using the mysqldump command. Aptana has several tools for managing your database, including the popular phpMyAdmin open source application. You can access this from Aptana, as shown below.

Figure 5. Accessing phpMyAdmin from Aptana Studio
Accessing phpMyAdmin from Aptana Studio

From the phpMyAdmin application, you can upload the file you created.

Figure 6. Uploading MySQL dump
Uploading MySQL dump

You can now move all the data you created locally to your database in the cloud. This process is mainly useful for an initial setup of your application. You could also generate SQL scripts locally, then run them on your staging and production databases, just as you would for an application running on your own hardware.


Designing and developing applications for the cloud can be tricky, depending on the kind of cloud computing platform you use. However, for many types of applications, using standardized open source technologies will greatly simplify your tasks. This approach is epitomized by the Aptana Cloud.

In this article, you learned how Aptana makes it easy to develop applications based on PHP and MySQL, and how to deploy them to the cloud. The next article in this "Realities of open source cloud computing" series will explore other parts of the life cycle for an application deployed on the cloud.



Get products and technologies



developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into Open source on developerWorks

Zone=Open source
ArticleTitle=Realities of open source cloud computing, Part 2: Developing for the cloud