[A Juju Adventure] Charming Lamp!

It is time to continue with my blog series on demonstrating how Ubuntu is the best environment to write up “connected” or “cloud backend” Android Apps.  As you might know, the Android SDK allows you to set up a sandboxed environment to develop Mobile apps in your desktop, using Juju  you can do the same for Cloud apps.

To walk you through how to put these great development tools together, I set out to accomplish:

  • Proof that you can access a Juju local environment from the Android Emulator  done!
  • Using a few charms from the charm store plus a custom one, set up a MySQL database that can be exposed through a web service with simple commands/steps
  • Develop a TODO list android app
  • Connect the android app and the webservice, so they talk to each other.

Today is time to set-up our own Cloud environment in a PC.  A good starting point for a web application is a LAMP stack. If you hope for you service to get popular, you might want to split out the database service and the web service into their own instances so they can be scaled easily.

When I set out to do this, I wanted to write an extremely simple PHP page that would expose a data table from a Mysql server.  I looked up the available charms on the store. I found that you had a lot of charms for existing apps, but none that had  the bare bones of a LAMP stack and just allowed you to install your own web pages. However, I did find a charm to deploy Mysql and a very handy tool to manage it (phpmyadmin). Taking this as a starting point I developed a generic LAMP charm.

The first thing the LAMP charm does is to install and configure a new instance with Apache and PHP5 in an LXC container. The new charm will then copy any files under /website  inside the charm folder structure, into /var/www. It also allows you to specify a Bazaar branch. It will clone the branch into the webserver and copy the contents to /var/www. I keep my TODO application for this exercise here.

Using juju, you can set up a relationship with a Mysql service. A Mysql database is created by default at this time. You can change the name of the database as a configuration options. If you provide a file called mysql_config either on the /website folder or in the root of you Bazaar branch, this will be used to configure further the Mysql database.

The charm will store the details of the relationship in /var/webconfig. In there you can also find opendb.php, a basic script that will open the connection to the MySQL database for you.

So lets get started! Clone the Lamp branch to a folder of your choice. I have it under “~/Mycharm/precise/lamp”. (If you need to get started with juju check my previous post here)

juju bootstrap

#step1 - deploy Mysql as a service.
juju deploy mysql

#step2 - deploy phpmyadmin tool
juju deploy phpmyadmin
juju set phpmyadmin password="password"

#this makes phpmyadmin public - exposes port 80/tcp
juju expose phpmyadmin

#step3 - link phpmyadmin and mysql so the can talk to each other
juju add-relation phpmyadmin mysql

#step4 deploy lamp from your local folder
juju deploy --repository ~/mycharm local:lamp

#step5 set up your bazaar branch and publish your website
juju set lamp website-bzr="lp:~vtuson/+junk/mytodo_web"
juju expose lamp

#step6 configure your database and link lamp and mysql services
juju set lamp website-database="android_todo"
juju add-relation lamp mysql

Once Juju has completed all the commands, run “juju status”. Now go to the ip address for the LAMP services and visit the databaseweb.php page (e.g. http://192.168.122.174/databaseweb.php) , you get this rather ugly table:

Id Todo Is it starred
1 hello this is a sample 1
2 yes it works! 0

This table is displaying the contents of a Mysql database. You will get the same data if you visit your Myphpadmin service:

So there you are a full and scalable LAMP stack in your PC!

If you want to update the web service by pulling the latest version of the Bazaar branch, just run the following commands:

juju set lamp bzr-update="yes"
juju set lamp bzr-update=

With my web developer “hat” on, I can now hand this charm over to my Android app developer. They will be able to set up exactly the same environment locally to test their app without using expensive server time.

So “Using a few charms from the charm store plus a custom one, set up a MySQL database that can be exposed through a web service with simple commands/steps” – DONE!

About these ads

8 Responses to [A Juju Adventure] Charming Lamp!

  1. scooby says:

    wow, this is cool. especially the “add-relation” functionality.

  2. Pingback: [Juju Adventure] Android ToDo and Juju « Victor Palau's Blog

  3. Pingback: [Juju Adventure] Live testing « Victor Palau's Blog

  4. Edward says:

    Hi Victor, just what I have been looking for thanks. However, having a few issues following. If I deploy Lamp as I would Mysql it doesn’t create a var/www folder. And, I have yet to work-out how to clone lamp to a local folder. Can you help? thanks Edward

    • Victor Palau says:

      /var/www is created by apache, so the charm must be failing to install. Are you running it locally or ec2 or other? Are you using 12.04? If you are running it locally, I suggest you run juju debug-log in a different terminal and have a look for errors. Also, when you run juju status, is the lamp instance started?

      • Edward Lee says:

        Thanks for the prompt reply. I pretty sure it start correctly — I destroyed the environment afterwards. Such is the power of Juju! Yep, running it locally on a brand new Dell XPS13 developer model. I will reinact the process through lunch and let you know how it goes. Thanks for your feedback.

      • Victor Palau says:

        Alright, check the logs and drop by #juju in irc freenode if you can

      • Edward says:

        Been inundated at work, so haven’t got back to juju yet — seen your reply to my earlier post on Ask. Thanks for clarifying that. So best for me to put my App on Bazaar first, then SSH’ing in. Will let you know if any problems. Thanks for taking timeout to help me; really appreciate it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: