Setting up Scalr with Ubuntu 12.04 Server and Predis

08 Feb
08/02/2013

Part of my work at acceleract is to build highly scalable web applications – mostly driving RESTful APIs for mobile clients these days.

The infrastructure powering these scalable PHP applications can get quite complex. For example, for a current client I’m running two load balancers which dispatch traffic to four app servers each using a powerful master-slave MySQL cluster and four master-slave Redis Key/Value stores for fast delivery of in-memory hashes. For all of this, I currently mostly use Ubuntu 12.04 server.

Naturally, I’m leveraging Amazon EC2, a very reliable, advanced PaaS (Platform-as-a-Service) provider for my infrastructure needs. While Amazon does a great job virtualizing all sorts of servers, the Cloud Management capabilities it offers are somewhat limited.

Therefore I recently took a deeper look into Scalr.

Scalr is a modern, fully open sourced Cloud Management solution that simplifies the art of setting up multi-tiered infrastructures and provides great means for auto-scaling. Exactly what my clients need.

I ran into some subtle issues and specialities on my journey with Scalr and thought, I might give back some of the findings to the community for others to save some time.

Here is the target setup I wanted to achieve:

  • Ubuntu 12.04 64bit with Amazon EBS storage
  • Daniele Alessandri’s fantastic Predis PHP client library installed
  • Increased PHP <> Redis performance via the phpiredis.so extension
  • Automated installation of libhiredis compiled from its source
  • Seamless, GitHub based deployment of the PHP application

Turns out, all of this can be achieved with Scalr, but it requires some scripting and setup. Here is the step by step guide. I assume, that you do understand the basics of the Scalr Control Panel.

First we need to add some scripts.

Cleaning /var/www

Unfortunately, the way Scalr set up its built-in scripts, a deployment configured via the Deployments tab of a Role fails, if the target directory is not empty. Ubuntu moves an index.html and phpinfo.php file into /var/www – which causes Scalr deployment to fail complaining about a non-empty directory.

So the first thing you should do is add a script that cleans /var/www:

Attach this to the HostInit event and give it an execution order of 20. Important: Make sure you set Where to “That instance only”, otherwise it’ll run on all instances whenever it gets triggered on a single instance. (I know, this bit sounds a bit confusing and believe me, I fell for it, too…)

Modifying PHP’s include_path

The default PHP distribution that ships with Ubuntu sets no include_path. PHP’s default (/usr/share/php) kicks in which is not ideal, as Ubuntu uses /usr/share/php5 instead.

Create another script to add the include_path directive to php.ini:

Again, add this to the HostInit event and set the execution_order to 10.

Installing libhiredis, Predis and phpiredis

Finally, we are all set to install the Redis libraries, PHP extensions and configure everything.

Add the following script

and add it to the HostUp event.

You’re all set.

That’s it. Launch your Farm and you should get a perfectly configured app server with the phpiredis extension ready to go and Predis available in the adjusted include path.

Hope this might help some Scalr fans out there.


Tags: ,
1 reply
  1. Sebastian Stadil says:

    Excellent write-up.

    One more tip for your readers: Deployments come with pre- and post- deploy scripts that you can use for cleanup. You can also use them to orchestrate more complex, multi-step deployments such as when you are deploying your application to a new directory, and then symlink LATEST to it.

    I also seem to miss text in “Add the following script [...] and add it to the HostUp event.” under #Installing.

    Thanks!

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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

* Copy This Password *

* Type Or Paste Password Here *

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>

© Copyright 2013 by Ralf Rottmann. rottmann.net is a work in progress by Ralf Rottmann. This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
If you would like to make use of any of the content you see here, please contact the author.