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.
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
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
<?php // ** 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
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
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
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.
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
Figure 5. Accessing phpMyAdmin from Aptana Studio
From the phpMyAdmin application, you can upload the file you created.
Figure 6. 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.
- Start with Realities of open source cloud computing, Part 1, which outlines the benefits of cloud computing, the types of clouds, and the high-level choices in cloud computing platforms. Then read Part 3 to learn about several open source tools and technologies to help you administer your application in a cloud.
- Discover why cloud computing is important, how to get started, and where to learn more about it in the developerWorks Cloud computing space.
- "Web development with Eclipse Europa, Part 2" explains how easy it is to develop PHP applications using a different set of Eclipse plug-ins, collectively known as the PHP Development Toolkit (PDT).
- "PHP frameworks, Part 1: Getting started with three popular frameworks" is the first part in a series that looks at three widely used PHP frameworks — Zend, symfony, and CakePHP — examining their similarities and differences while building and extending a sample application in each of the three frameworks.
- Read "Easy Ruby development, the Eclipse way" for information about some of the plug-in's features. Whether you use The Aptana Cloud or Heroku for your Ruby on Rails applications, you will want to look at Aptana's RadRails.
- Many of the cloud computing platforms rely on Xen to virtualize Linux environments. "A moment of Xen: Virtualize Linux to test your apps" explores this key technology.
- The Aptana Cloud Docs Wiki has a load of information on the Aptana Cloud.
- Learn all about WordPress.
- "Creating mashups on the Google App Engine using Eclipse" has all the details about build applications for the Google App Engine.
- "Connecting Apple's iPhone to Google's cloud computing offerings" discusses making the cloud accessible on mobile devices.
- "Data integration with Salesforce CRM using IBM InfoSphere Information Server" explores how Salesforce makes it data accessible to your applications.
- To listen to interesting interviews and discussions for software developers, check out developerWorks podcasts.
- Stay current with developerWorks' Technical events and webcasts.
- Follow developerWorks on Twitter.
- Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
- Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.
- Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand demos.
Get products and technologies
- Innovate your next open source development project with IBM trial software, available for download or on DVD.
- Download IBM product evaluation versions or explore the online trials in the IBM SOA Sandbox and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
- Participate in developerWorks blogs and get involved in the developerWorks community.