Installing Emoncms on Raspberrry Pi 2

Emoncms can do some great input processing and visual dashboards, along with many other things. Below is the process I used to install it on a Raspberry Pi 2 using Raspian.

Install Dependencies

Install all the dependencies.

sudo apt-get install apache2 mysql-server mysql-client php5 libapache2-mod-php5 php5-mysql php5-curl php-pear php5-dev php5-mcrypt git-core redis-server build-essential python-serial python-configobj python-pip python-dev

During this install, it will prompt you for further information. Install pecl dependencies (redis and swift mailer)

sudo pecl install redis
sudo pear channel-discover
sudo pear install log4php/Apache_log4php

Add pecl modules to php5 config

sudo sh -c 'echo "" > /etc/php5/apache2/conf.d/20-redis.ini'
sudo sh -c 'echo "" > /etc/php5/cli/conf.d/20-redis.ini'

Configure dependencies


Configure redis to run without logging or data persistence.

sudo nano /etc/redis/redis.conf

Comment out redis log file and all the redis saving.

# logfile /var/log/redis/redis-server.log
# save 900 1
# save 300 10
# save 60 10000

Then restart the Redis service

sudo /etc/init.d/redis-server start


Emoncms uses Apache to route requests, so modrewrite needs to be enabled.

sudo a2enmod rewrite

Modify the Apache2 config to allow rewrite.

sudo nano /etc/apache2/sites-enabled/000-default

Change (line 7 and line 11), AllowOverride None to AllowOverride All. Comment out line # CustomLog ${APACHE_LOG_DIR}/access.log combined Comment the access log to other-vhosts (add #)

sudo nano /etc/apache2/conf.d/other-vhosts-access-log

Now Reboot the Pi

sudo reboot

Install Emoncms

For the install Emoncms, it will be installed from the git repository for Emoncms. First, lets setup the web directory and permissions.

cd /var
sudo chown pi www

Download Emoncms from the git repository. For this we’re using a cloning a specialised version of Emoncms which has been designed to write less to the SD Card.

cd www
git clone -b bufferedwrite

Configure Emoncms


Lets setup the mysql database for Emoncms. If you would like to move the mysql database to another location (for easier backup,etc), now is the time to do it. For this, I’ve chosen to move the Mysql database to /home/pi/data/mysql. I first create the directory and then copy the mysql data accross.

mkdir /home/pi/data/mysql
sudo cp -rp /var/lib/mysql/. /home/pi/data/mysql

Now update the mysql configuration file to use the new location.

sudo nano /etc/mysql/my.cnf

change line datadir to /home/pi/data/mysql Create the Emoncms database.

mysql -u root -p

This will prompt you for a password and the following SQL will create the database.

mysql> CREATE DATABASE emoncms;

Now create a user and assign permissions that Emoncms will use to access the mysql databse. In the commands below, update username and password to suit your choice.

mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON username . * TO 'username'@'localhost';

Data directory

Now we create some directories were the Emoncms’ feed engines (phpfina and phptimeseries) will store data. I chose /home/pi/data/.

mkdir /home/pi/data/phpfina
mkdir /home/pi/data/phptimeseries
sudo chown www-data:root /home/pi/data/phpfina
sudo chown www-data:root /home/pi/data/phptimeseries

Emoncms Configuration settings

Lets setup the configuration file for Emoncms. We copy the default.settings.php to settings.php.

cd /var/www/emoncms
cp default.settings.php settings.php

Now we update the settings to suit this installation of Emoncms.

nano settings.php

Update the following things: Database Settings. Update these to the username and password you created previously when setting up Mysql.

$username = "USERNAME";
$password = "PASSWORD";

If you chose a different location to store your data directory earlier, update these lines to suit your data directories.



Setup the feedwriter script as a service.  Copy the service script to /etc/init.d/, update permissions and enable for service.

sudo cp /var/www/emoncms/run/feedwriter /etc/init.d/
sudo chmod 755 /etc/init.d/feedwriter
sudo update-rc.d feedwriter defaults

Now go to a web browser and go to the emoncms website. Update the IP-Address below to your host.


Click Register and create yourself a new Admin user. After you have successfully logged in and do not want to create any other users for this Emoncms, it is best to disable the register functionality. To do this, we edit the settings again.

nano settings.php

And change $allowusersregister to FALSE.

$allowusersregister = FALSE;

As you have now gone through the initial setup for Emoncms, you can also disable the dbtest.

$dbtest = FALSE;


The following log entries should be created and help with this.

tail -f /var/log/feedwriter.log
tail -f /var/log/emoncms.log



Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s