Emoncms on DietPi

Introduction

WARNING

The Install of EmonCMS has moved on since I wrote this and this guide is now depreciated

I am a huge fan of DietPi – lightweight and fast, runs an a large number of SBCs. The aim here was to build a local EmonCMS server as simply as possible. Doing it even from a Rasbian Stretch minimal image can be a bind – DietPi makes some of the tricky bits as easy as selecting from a menu. Not everything can be done that way and some command line effort is required. I started with a fresh V6.16 DietPi install. Well actually it is a base VM image I have that I simply updated. Yes, DietPi runs very happily on a VM, is much quicker than on a Pi and no issues with SD Cards corrupting. In addition, you can take snapshots so less risk of ruining an installation!

The other aspect is that these instructions will install a LLAP stack of Lightppd, PHP7 and MariaDB. Personally I think Apache is rather bloated.

Setting up

DietPi-Config

The initial setting up is best done via the DietPi interface. Simply type dietpi-config to enter the menu system.

  1. DietPi-config – Advance options – Time sync mode – time sync daemon + drift (more reliable time)
  2. DietPi-config – Security options – change root password and hostname (optional)
  3. DietPi-config – Network Options: Adapters  – fixed IP and turn off IPV6 (optional)

DietPi-Software

DietPi has a menu system for installing a number of different software packages. You can either do these installs via the menu system or shortcut it by using the command line syntax dietpi-software install [ID] (except for the SSH change).

  1. Avahi daemon [152] – gives you a hostname on your network.
  2. Install GIT [17]
  3. Install LLAP [82] – It will suggest you do not need this but go ahead anyway.
  4. DietPi-Software – SSH Server – OpenSSH (Optional – allows WinSCP to transfer files – replaces defualt dropbear)
  5. Install redis-server [91] – Only required if you are going to use Redis, but it is suggested you do!
  6. Install Mosquitto [123] – Only required if you intend to run an MQTT broker on this machine (I run the broker on my HASSIO instance). Not needed to publish and subscribe to topics.

Command line installs

Next you need to install a few bits directly. NOTE in DietPi you do most things as root (you can setup other users, I never bother) so sudo is not required.

  1. apt-get -y install php7.0-dev – This gives you the phpenmod and phpdismod commands
  2. apt-get -y install build-essential – Is used by PECL to build compile the redis and mqtt php modules.
  3. apt-get -y install php-pear
  4. apt-get -y install mosquitto-clients – Optional, required if you want to debug MQTT.
  5. pecl channel-update pecl.php.net
  6. pecl install redis-3.1.6 – This is the PHP extension for REDIS – the version is important.
  7. printf "extension=redis.so" | sudo tee /etc/php/7.0/mods-available/redis.ini 1>&2
  8. phpenmod redis – Enable the PHP Redis extension.

MQTT [edit]

I suddenly realised that I had not included how to install MQTT. The simplest way is to follow this guide (remembering you do not need sudo).

Configure Lighttpd

nano /etc/lighttpd/lighttpd.conf – Edit the Lighttpd configuration:

Add in mod_rewrite

And add these lines at the end…

Either restart Lighttpd or reboot the server (I like to do the latter) systemctl restart lighttpd

EmonCMS

I was going to refer to the main documentation for this, but it is somewhat out of date and inconsistent so…

The Base System

  1. cd /var/www
  2. git clone -b master https://github.com/emoncms/emoncms.git You may want to use the stable branch instead.

Setup The Database

  1. mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); DELETE FROM mysql.user WHERE User=''; DROP DATABASE IF EXISTS test; DELETE FROM mysql.db WHERE Db='test' OR Db='test_%'; FLUSH PRIVILEGES;"
  2. sudo mysql -e "CREATE DATABASE emoncms DEFAULT CHARACTER SET utf8;"
  3. mysql -e "CREATE USER 'emoncms'@'localhost' IDENTIFIED BY 'emonadmin'; GRANT ALL ON emoncms.* TO 'emoncms'@'localhost'; FLUSH PRIVILEGES;"

Create Data Directories

  1. mkdir /var/lib/{phpfiwa,phpfina,phptimeseries}
  2. chown www-data:root /var/lib/{phpfiwa,phpfina,phptimeseries}
  3. chmod 755 /var/lib/{phpfiwa,phpfina,phptimeseries}

Setup Log file

  1. touch /var/log/emoncms.log
  2. chmod 666 /var/log/emoncms.log
  3. chown root:www-data /var/log/emoncms.log

Edit EmonCMS Settings

  1. cd /var/www/emoncms && cp default.settings.php settings.php
  2. nano /var/www/emoncms/settings.php

First run

Open a browser window to [YourIpAddress]/emoncms. At the user prompt click on Register. Register a user then log in. First stop is the administration page and check database. Everything should now be ready to go!

You may wish to add in some additional Modules.

You may also wish to enable MQTT for subscribing and publishing.

Facebooktwitterby feather
This entry was posted in DietPi, OpenEnergyMonitor, Technical - General. Bookmark the permalink.

2 Responses to Emoncms on DietPi

  1. Jeff says:

    Hi Is this the install for their new version.. as they are now in paid mode.. So this install is it fully local or send to the server.. ?
    Thanks

    • Brian says:

      Sorry, I’m not understanding the question. Is ‘their’ referring to the Emoncms software or DietPI?

      If Emoncms, this is a purely local install method of just the logging / visualization software not the paid for emoncms.org.

Leave a Reply