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.
- DietPi-config – Advance options – Time sync mode – time sync daemon + drift (more reliable time)
- DietPi-config – Security options – change root password and hostname (optional)
- 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).
- Avahi daemon [152] – gives you a hostname on your network.
- Install GIT [17]
- Install LLAP [82] – It will suggest you do not need this but go ahead anyway.
- DietPi-Software – SSH Server – OpenSSH (Optional – allows WinSCP to transfer files – replaces defualt dropbear)
- Install redis-server [91] – Only required if you are going to use Redis, but it is suggested you do!
- 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.
-
apt-get -y install php7.0-dev – This gives you the
phpenmod
andphpdismod
commands - apt-get -y install build-essential – Is used by PECL to build compile the redis and mqtt php modules.
- apt-get -y install php-pear
- apt-get -y install mosquitto-clients – Optional, required if you want to debug MQTT.
- pecl channel-update pecl.php.net
- pecl install redis-3.1.6 – This is the PHP extension for REDIS – the version is important.
- printf "extension=redis.so" | sudo tee /etc/php/7.0/mods-available/redis.ini 1>&2
- 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
1 2 3 4 5 6 7 |
server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_redirect", "mod_rewrite", ) |
And add these lines at the end…
1 2 3 4 |
url.rewrite-if-not-file = ( "^/emoncms/([^?]*)$" => "/emoncms/index.php?q=$1", "^/emoncms/([^?]*)\?(.*)$" => "/emoncms/index.php?q=$1&$2" ) |
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
- cd /var/www
- git clone -b master https://github.com/emoncms/emoncms.git You may want to use the stable branch instead.
Setup The Database
- 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;"
- sudo mysql -e "CREATE DATABASE emoncms DEFAULT CHARACTER SET utf8;"
- mysql -e "CREATE USER 'emoncms'@'localhost' IDENTIFIED BY 'emonadmin'; GRANT ALL ON emoncms.* TO 'emoncms'@'localhost'; FLUSH PRIVILEGES;"
Create Data Directories
- mkdir /var/lib/{phpfiwa,phpfina,phptimeseries}
- chown www-data:root /var/lib/{phpfiwa,phpfina,phptimeseries}
- chmod 755 /var/lib/{phpfiwa,phpfina,phptimeseries}
Setup Log file
- touch /var/log/emoncms.log
- chmod 666 /var/log/emoncms.log
- chown root:www-data /var/log/emoncms.log
Edit EmonCMS Settings
- cd /var/www/emoncms && cp default.settings.php settings.php
- 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.
by
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
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.