Installing EmonCMS in a FreeBSD Jail under NAS4Free

A while back I had posted a set of directions for installing EmonCMS in a FreeBSD jail under a home server software tool called NAS4Free. That server died and I found when I got new hardware, those directions no longer worked, as the various packages and ports under FreeBSD changed enough that the server was not functional when installed under those directions. I tried and tried but eventually gave up and pointed my EmonTX to the UK server.

Bill Thomson decided to pick up the challenge because his brain was bored and he quickly solved it. So, thanks to him we now have working directions for those seeking to run their own EmonCMS under a nice home server package. Here are the updated directions. All thanks go to Bill - I only edited the directions...

1. Install NAS4Free

This is done by creating a LiveCD that will boot a FreeBSD loader which gives you options to install it onto a disk or USB flash drive. I divided a small SSD into OS, swap and data,  partitions,  but you could easily do this with a single OS partition on a flash drive, and mount a separate data drive for Emoncms. Once NAS4Free is installed, reboot the server and log in via your web browser.

In the NAS4Free web management tool

Enable the SSH server. Be sure to check the option to allow login as root

Mount at least one drive to contain the FreeBSD jail and Emoncms software. I refer to this mounted drive as /mnt/{your storage drive name} in the directions that follow.

Install 'The Brig' NAS4Free extension to create and manage FreeBSD jails

Download The Brig from:

SSH to the NAS4Free server. Login as root with the WebGUI password

mkdir /mnt/{your storage drive name}/thebrig
chmod 755
sh /mnt/{your storage drive name}/thebrig

Reboot the server

Initialize The Brig

Log into the NAS4Free WebGUI and click on the new Extensions menu to enter The Brig. The first time you go there, it will walk you through the setup. Download the FreeBSD base and lib32 tarballs. They are needed to install a full version of FreeBSD in the jail we are creating.

Create the jail

Click to create a new FreeBSD jail with the following options:

Jail number: 1 (Defaults to 1 for the first jail)

Jail Name: Your choice, but I called my emon

Jail Type: Full

Jail Interface: LAN

Jail IP address: choose an IP address for the jailed FreeBSD. I don't think allowing this to be set dynamically, i.e. DHCP, will work, as elsewhere in the directions, you'll need to enter  this IP into various configuration files. The file server will have two IP addresses for one physical network connection. One will be for NAS4Free, the other, for the jailed FreeBSD running Emoncms. In my case, the jail address was

Jail Start on boot: Check

mount devfs checked

Source from Archive: Check both the base and lib32 versions

Once complete, reboot, go back to this web page and verify that the jail is running.

2. Install AMP (Apache/MySQL/PHP) in the jail

SSH to the original NAS4Free server just like before

Once in, verify the status of the jail by typing 'jls' – you should see your jail listed with the IP address you gave it.

Enter the jailed FreeBSD with the following command: 'jexec x csh' (x is the jail number if you have more than one jail). All of the remaining commands are entered in the jailed FreeBSD.

Install package manager, git-lite, and the nano text editor – confirm all prompts

pkg install git-lite
pkg install nano

Install Apache 2.4

pkg install apache24

Add the following line to rc.conf to enable apache to start at boot time:

echo 'apache24_enable="YES"' >> /etc/rc.conf

Edit configuration file

nano /usr/local/etc/apache24/httpd.conf

Uncomment the LoadModule rewrite_module line

Change “none” to “all” in the AllowOverride line (<Directory "/usr/local/www/apache24/data"> section)

Add the next two lines to the <IfModule mime_module> section

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Add the following two sections to the end of httpd.conf

<FilesMatch "\.php$">
sethandler application/x-httpd-php
<FilesMatch "\.phps$">
sethandler application/x-httpd-php-source

Install MySQL

pkg install mysql56-server
echo 'mysql_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/mysql-server start

Secure your mysql database with this script: mysql_secure_installation

accept all suggested options

Create Emoncms database

mysql –u root –p (you’ll be prompted for the root password)
create database emoncms;

Install remaining packages

pkg install mod_php56 php56-mysql php56-mysqli php56-curl php56-mcrypt
php56-json php56-gettext php56-session php56-ctype php56-filter php56-hash

Edit php.ini

nano /usr/local/etc/php.ini

Uncomment (or add) the line that reads:

date.timezone = "America/New_York" (put your timezone here)

For a list of supported timezones, see

Restart Apache

apachectl restart

Test PHP is working and attached to Apache

Create a test php file with the following command:

echo "<? phpinfo(); ?>" > /usr/local/www/apache24/data/test.php

Direct your browser to: {your jail IP address}/test.php

You should see a long list of all the PHP settings and extensions. If not, or if your web browser wants you to view a PHP file, then PHP and Apache are not linked.

3. Install Emoncms

cd /usr/local/www/apache24/data
git clone
mkdir –m 0777 /usr/local/emoncmsdata
mkdir –m 0777 /usr/local/emoncmsdata/phpfiwa
mkdir –m 0777 /usr/local/emoncmsdata/phpfina
mkdir –m 0777 /usr/local/emoncmsdata/phptimeseries
mkdir –m 0777 /usr/local/emoncmsdata/phptimestore

Set emoncms database settings

cd /usr/local/www/apache24/data/emoncms
cp default.settings.php settings.php
nano /usr/local/www/apache24/data/emoncms/settings.php

enter the mysql username and root password

    $username = "root";

    $password = "*****";

    $server   = "localhost";

    $database = "emoncms";

change directories to




Direct your browser to

The emoncms logon/register screen should be displayed

Bill Thomson's picture

Re: Installing EmonCMS in a FreeBSD Jail under NAS4Free

Thanks for the "atta boy," Dan!

I enjoyed "workin' the problem," and learned a lot about FreeBSD in the process.

Good to hear you've got your system online again...





Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.