Installing Scalr 3.5 Open Source on Ubuntu 12.04

This is an update on an older post of mine, one of my first articles regarding cloud computing. Much has changed since since 2008 when I have wrote this article “How to install Scalr on Ubuntu 8.10 EC2 Instance“.

For example the Ubuntu has evolved to 12.04 LTS (I am using LTS 64bit for this howto) and Scalr is now version 3.5. One thing didn’t change: it’s still a royal PITA to get Scalr open source working. Hopefully this howto will help you to install Scalr on your server. It doesn’t cover operating Scalr and other things, which I will address in future posts, if there is enough interest.

After you have installed Ubuntu 12.04 64bit server edition to your server or virtual machine the way you like it it’s time to start the update process:

apt-get update && apt-get upgrade

Now you are ready to run tasksel and select the following roles for your server: OpenSSH, DNS server, LAMP server

You will need to install some dev packages before going anything else:

apt-get install libcurl4-gnutls-dev make librrd-dev

Now it’s time for PHP5 related extensions:

apt-get install php5-curl php-gettext php-net-socket php5-mcrypt php-xml-serializer libssh2-php php-soap php5-snmp php5-rrd
pecl install pecl_http
echo "" >/etc/php5/conf.d/pecl_http.ini
pecl install rrd
echo "" >/etc/php5/conf.d/rrd.ini

Time to get Scalr code:

cd /tmp
tar zxvf scalr35
cd scalr-3.5.r7704
cp -r app /var/www/
chown -R www-data:www-data /var/www/app

Create new database and import sql from sql/scalr:

mysql -p
mysql> CREATE DATABASE scalr CHARACTER SET latin1 COLLATE latin1_swedish_ci;
mysql> grant all privileges on scalr.* to scalr@localhost identified by 'password';
mysql> flush privileges;
mysql> quit
mysql -p scalr <sql/scalr.sql

While doing that import I’ve got a nice error:
ERROR 1054 (42S22) at line 2222: Unknown column ‘architecture’ in ‘field list’
1) Drop database
2) Search sql/scalr.sql for “CREATE TABLE IF NOT EXISTS `role_images`” and add after platform:

`architecture` varchar(25) DEFAULT NULL,
`os_family` varchar(25) DEFAULT NULL,
`os_name` varchar(25) DEFAULT NULL,
`os_version` varchar(25) DEFAULT NULL,
`agent_version` varchar(25) DEFAULT NULL,


Configuration of Scalr is quite simple:

cd /var/www/app/etc
cp config.ini-sample config.ini
edit config.ini

Cron jobs required by Scalr? Just type crontab -e and add the following lines:

*/2 * * * * /usr/bin/php -q /var/www/app/cron-ng/cron.php --Poller
* * * * * /usr/bin/php -q /var/www/app/cron/cron.php --Scheduler2
*/10 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --MySQLMaintenance
* * * * * /usr/bin/php -q /var/www/app/cron/cron.php --DNSManagerPoll
17 5 * * * /usr/bin/php -q /var/www/app/cron/cron.php --RotateLogs
*/2 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --EBSManager
*/20 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --RolesQueue
*/5 * * * * /usr/bin/php -q /var/www/app/cron-ng/cron.php --DbMsrMaintenance
*/2 * * * * /usr/bin/php -q /var/www/app/cron-ng/cron.php --Scaling
*/5 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --DBQueueEvent
*/2 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --SzrMessaging
*/4 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --RDSMaintenance
*/2 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --BundleTasksManager
* * * * * /usr/bin/php -q /var/www/app/cron-ng/cron.php --ScalarizrMessaging
* * * * * /usr/bin/php -q /var/www/app/cron-ng/cron.php --MessagingQueue
*/2 * * * * /usr/bin/php -q /var/www/app/cron-ng/cron.php --DeployManager
*/2 * * * * /usr/bin/php -q /var/www/app/cron/cron.php --UsageStatsPoller
* * * * * root /usr/bin/php -q /var/www/app/cron-ng/cron.php --SNMPStatsPoller

Time to add a Virtual Host:

cat <<EOF> /etc/apache2/sites-available/scalr
<VirtualHost *:80>
DocumentRoot "/var/www/app/www"

<Directory "/var/www/app/www">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

Enable required Apache modules and site and restart everything:

a2ensite scalr
a2enmod rewrite
service apache2 restart

DNS managed by bind9:

chmod g+w /etc/bind/named.conf
echo 'include "/var/named/etc/namedb/client_zones/zones.include";' >> /etc/bind/named.conf
mkdir -p /var/named/etc/namedb/client_zones
chown root.bind /var/named/etc/namedb/client_zones
chmod 2775 /var/named/etc/namedb/client_zones
echo ' ' > /var/named/etc/namedb/client_zones/zones.include
chown root.bind /var/named/etc/namedb/client_zones/zones.include
chmod g+w /var/named/etc/namedb/client_zones/zones.include

To get rid of nasty AppArmor warnings and errors edit /etc/apparmor.d/usr.sbin.named and add:

/var/named/etc/namedb/client_zones/zones.include rw,

And finish it by restarting AppArmor and bind9:

service apparmor restart
service bind9 restart

Open your browser and go to Default username/password: admin/admin.

If you have issues or you need more info please feel free to comment 🙂

Scalr errors after install

After installing Scalr and adding a client I’ve tried to add an application to test out my setup. But at the second step I’ve got an alert saying:

Error Type: LoadXML
Description: Incorrect XML

A quick look at the apache log revealed the problem:

File does not exist: /var/scalr/app/www/farm_amis.xml

I thought that maybe I’ve missed a file so I did a svn checkout of scalr repository and tried to find the specified file:

apt-get install subversion
svn checkout scalr-read-only
find scalr-read-only -name farm_amis.xml -type f

Nothing came up. Weird. After a bit of looking around I’ve found a file called farm_amis_xml.php. So in fact farm_amis.xml was only a mod_rewrite directive.

Time to fix it, enable mod_rewrite and .htaccess files for apache2:

Edit /etc/apache2/sites-available/000-default and change the lines containing

AllowOverride None


AllowOverride All

Go to /etc/apache2/mods-enabled and execute the following command:

ln -s ../mods-available/rewrite.load

Restart apache2 server and everything should be ok:

/etc/init.d/apache2 restart

How to install Scalr on Ubuntu 8.10 EC2 Instance


If Amazon EC2 doesn’t ring a bell to you, chances are that you are looking at the wrong page to find solutions for your problems. EC2 stands for Elastic Compute Cloud and it’s a service offered by Amazon. I will not enter in details about the advantages of using it, since this is not the scope of this post. You can read more about it here:

Scalr is a fully redundant, self-curing and self-scaling hosting environment utilizing Amazon’s EC2. You basically can build farms of Amazon’s instances that can do load balancing using nginx, serve web pages using Apache 2, use MySQL master-slave servers or maybe you may want to define your own roles.

The beauty of this is that you don’t have to monitor the health of your server infrastructure, scalr will do it for you. If a node type gets overloaded scalr will launch another instance to spread the load and the cluster will be reconfigured.


Generate a new key for scalr instance:

ec2-add-keypair scalr-keypair > id_rsa-scalr-keypair

Edit id_rsa-scalr-keypair so it begins with


and is terminated with


Make sure you have the correct permissions for this key:

chmod 600 id_rsa-scalr-keypair

If everything went ok you should see your new key when executing


Choosing the right AMI:

For the instance we will be using ami-7806e211 which is an AMI containing a base install of Ubuntu 8.10 Intrepid Ibex Release. More details here.

Start the instance:

ec2-run-instances -z us-east-1a -k scalr-keypair ami-7806e211

You will get some output, look for the line that begins with INSTANCE and write down somewhere the id of the instance (i-XXXXXXXX) and the address of the instance( The status of your instance should be pending.

Check in a couple of minutes the status of your instance:

ec2-describe-instances i-XXXXXXXX

When the status is running it means that your instance is ready for work. You should have at least ssh and web ports open(22 and 80). If you are not sure execute the following commands:

ec2-authorize default -p 22
ec2-authorize default -p 80

Now connect to your instance using ssh:

ssh -i id_rsa-scalr-keypair -v

First time you connect you will be asked if

Are you sure you want to continue connecting (yes/no)?

Type yes and you should be the happy owner of a fresh Ubuntu Intrepid Ibex instance.

Update your system now:

apt-get update
apt-get upgrade

After the update is completed, logout and reboot your instance:

ec2-reboot-instances i-XXXXXXXX

Installing required software:

Reconnect to your instance and install MySQL server and php extensions:

apt-get install bind9 mysql-server mysql-client apache2 php5-cli libapache2-mod-php5 php5-mysql php5-mcrypt php5-mhash

When you install MySQL server you will be prompted to setup a password for the root account. Don’t forget it, you will need it. Also you will have to restart Apache2 server after you finish installing everything, like this:

/etc/init.d/apache2 restart

You could also download their php script that checks if your system has all the prerequisites

mv checkenvironment.php /var/www/
chmod a+r /var/www/checkenvironment.php

Now point your browser to and see if everything it’s ok.

Most likely you will get only these 2 errors:

• Cannot find SSH2 functions. Make sure that SSH2 Functions enabled.
• Cannot find SNMP functions. Make sure that SNMP Functions enabled.

Here is how to quick fix it:
Adding SSH2 support to PHP5, better known as: why don’t we have php5-ssh2?

apt-get install php5-dev php-pear libssh2-1 libssh2-1-dev

Thought it will be easy? Not so quick. Try to install it with:

pecl install ssh2 "channel://"

I got an error saying:

ERROR: `make' failed

Great! Let’s fix that stupid error. Edit the file /tmp/pear/download/ssh2-0.10/ssh2.c and replace the line containing:

#if LIBSSH2_APINO < 200412301450


#if false

Go to directory /tmp/pear/download/ssh2-0.10/ and compile the stuff manually:

make && make install
echo >> /etc/php5/apache2/php.ini

I don’t get it why they don’t fix this thing. A lot of people are having this problem and are complaining!

Luckily for you and me snmp is a breeze, it is already in repositories:

apt-get install php5-snmp

Restart apache server and check now if you have all the required extensions for scalr. You should have them.

Getting the latest version of Scalr:

At the time of writing this article latest version was 1.0 RC2
Go to Scalr download page and copy the link to the latest release. Download it using wget:


Extract it:

tar zxvf scalr-1.0RC2.tar.gz

Create database for scalr and import the sql:

mysqladmin -p create scalr
mysql -p scalr < scalr/sql/database.sql

Put the scalr application in /var/scalr and change permissions as suggested in the spartan documentation of scalr:

mkdir /var/scalr && cp -R scalr/* /var/scalr/
chmod 777 -R  /var/scalr/app/cache /var/scalr/app/cron/ /var/scalr/app/etc/.passwd

ATTENTION: I’m not planing on using this instance for anything else except scalr. Also this is a clean install so I don’t have anything of interest in /var/www. Read carefully the following first line:

rm -rf /var/www/
ln -sf /var/scalr/app/www /var/
chmod a+rX -R /var/www

Edit the file /var/scalr/app/etc/config.ini and update it to your values:

driver=mysql ;Actually mysql is the only option here - mysqli doesn't support nconnect(), which is essential for PCNTL (which is essential for crobjobs)
host = "localhost"
name = "scalr"
user = "root"
pass = "*YOUR PASS HERE*"

TO DO: make a mysql user for scalr.

Put your EC2 access certificate into /var/scalr/app/etc/cert-XXXXXXXXXXXX.pem
Put your EC2 private key into /var/scalr/app/etc/pk-XXXXXXXXXXXX.pem
ATTENTION: This part is a bit tricky. If you don’t put the right settings you will not be able to start instances. I warned you!
Login to Amazon AWS and go to Home->Your Account->Access Identifiers
Go to and login with admin/admin
Go to Settings->Core Settings. Modify the following fields:
Password: duh!!! change it!
Email: your email address here
Account ID: AWS Account Number, it’s called Account Number in AWS and it’s top right. Remove the ‘-‘ from the number
Key Name:Scroll down in AWS untill you see Your X.509 Certificate: Copy everything between ‘cert-‘ and ‘.pem’. Also XXXXXXXXXXXXXX is the string in the filenames of cert-XXXXXXXXXXXXX.pem and pk-XXXXXXXXXXX.pem. If they don’t match you will have problems.
Access Key:Look for Your Secret Access Key: in AWS and click on Show. Copy the string.
Access key ID: is Your Access Key ID: in AWS.

Hit save.

setting crontab:

Type crontab -e and add the following lines to cron:

* * * * * /usr/bin/php -q /var/scalr/app/cron/cron.php --Poller
1 1 * * * /usr/bin/php -q /var/scalr/app/cron/cron.php --RotateLogs
*/15 * * * * /usr/bin/php -q /var/scalr/app/cron/cron.php --MySQLMaintenance
*/6 * * * * /usr/bin/php -q /var/scalr/app/cron/cron.php --DNSMaintenance
*/3 * * * * /usr/bin/php -q /var/scalr/app/cron/cron.php --DNSZoneListUpdate
*/2 * * * * /usr/bin/php -q /var/scalr/app/cron/cron.php --DBQueueEvent
*/11 * * * * /usr/bin/php -q /var/scalr/app/cron/cron.php --Cleaner

You are done. I hope.

How to terminate the instance:

I thought to write down instructions on how to terminate an instance. You should know how, but just in case, here it is how to stop the instance forever and not pay for it anymore. ATTENTION: terminate will really delete the instance so there is no way you can reconnect to it or recover it. Double check what instance you terminate!

ec2-terminate-instances i-XXXXXXXX