Categories
Connected Farm

farmOS Version 2 Raspberry Pi Install.

Recently I started using farmOS as my farm management software, a major new version has just been released which requires a fresh install and migration. The following is the process I used to setup farmOS V2 on a Raspberry Pi using Docker.

I’d recommend a Raspberry Pi capable of running 64bit Pi OS, I’m using a Pi3 and 64bit Pi OS Lite. I’m going to assume anyone following this can install the Pi OS and login to it.

Warning: if you have data to migrate from farmOS V1 make sure to make a backup, the old and new data base instances will need to be connected to the new farmOS V2 for migration, which will be covered in a later post, see: https://farmos.org/hosting/migration/

The following commands will install and configure Docker:

curl -fsSL get.docker.com | sh

sudo apt-get install -y uidmap

dockerd-rootless-setuptool.sh install

sudo systemctl start docker

sudo systemctl enable docker

sudo usermod -aG docker $USER

newgrp docker

sudo apt install docker-composeCode language: JavaScript (javascript)

Next well clone the farmOS Git Repository and build the Docker image :

sudo apt install git

mkdir git

cd git

git clone -b 2.x https://github.com/farmOS/farmOS.git

cd farmOS/docker

sudo docker build -t farmos .Code language: PHP (php)

It may take some time for the build process to complete so be patient. When it is finished the last line of the output should read “Successfully tagged farmos:latest”. Next we can create a new folder for the farmOS install:

cd /home/pi

mkdir farmOS

cd farmOS

nano docker-compose.yml

Paste the following into nano / modify if you’d like to use a different DB:

version: '3'
services:
  db:
    image: postgres:12
    volumes:
      - './db:/var/lib/postgresql/data'
    ports:
      - '5432:5432'
    environment:
      POSTGRES_USER: farm
      POSTGRES_PASSWORD: farm
      POSTGRES_DB: farm

  www:
    depends_on:
      - db
    image: farmos:latest
    volumes:
      - './www:/opt/drupal/sites'
    ports:
      - '80:80'



Code language: JavaScript (javascript)

CTRL-X to exit, then Y + Return to save.

The following command will start farmOS and the Database:

docker-compose up -d

If all has gone well it should be possible to continue the install by navigating to the IP address of the Raspberry Pi from any browser on the same network.

Chose Language:

If you’ve used a 32bit OS, then PHP may give a warning about 32bit dates running out in 2038, there is a continue anyway option at the very bottom.

Database Setup.

Host is IP address of the Pi or Database server if you’ve chosen another one. Database names and passwords were set in docker-compose.yml (I found Localhost doesn’t work, so make sure to use static IP addresses).

Farm Details:
Select Modules:

Optional Steps for remote access with SSL:

For remote access SSL is recommended and even required if you plan on using the farmOS field kit. This requires a Domain name and certificates from an SSL encryption authority, I use DuckDNS.org for domain name and LetsEncrypt.org for certificate files.

cd /home/pi

mkdir ssl

cd farmOS

docker-compose down

nano docker-compose.yml

Add the following to the end of the file:

 proxy:
    depends_on:
      - www
    image: nginx:latest
    volumes:
      - './nginx:/etc/nginx'
      - '/home/pi/ssl:/etc/nginx/certs'
    ports:
      - '80:80'
      - '443:443'
Code language: JavaScript (javascript)

CTRL-X to exit, then Y + Return to save.

Start and stop docker containers (to create volumes).

docker-compose up -d

docker-compose down

Add the Nginx config:

cd /home/pi/farmOS/nginx

sudo mkdir error_logs

sudo touch error_log.log

sudo nano nginx.conf

Copy and paste config:

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {

}

http {
  error_log /etc/nginx/error_logs/error_log.log warn;
  client_max_body_size 20m;

  server {
      listen 80;
      server_name yourdomain.duckdns.org;

      rewrite ^/(.*)$ https://$host$request_uri? permanent;
  }

  server {
    server_name yourdomain.duckdns.org;

    location / {
      proxy_pass http://www:80;

      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Host $host:443;
      proxy_set_header X-Forwarded-Port 443;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-Proto https;
    }

    listen 443 ssl;
    ssl_certificate /etc/nginx/certs/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/privkey.pem;
  }
}
Code language: PHP (php)

Modify with your domain name then CTRL-X to exit and Y to save.

Copy SSL Cert files into /home/pi/SSL. I have Home Assistant running on another Raspberry Pi and it uses the same domain name and has SSL certs and Samba Addon Running, so I just mount its SSL directory.

sudo mount -t cifs //HomeAssistantIP/ssl /home/pi/ssl -o username=yourusername,password=yourpassword

cd /home/pi/farmOS

docker-compose up -dCode language: JavaScript (javascript)

Finally forward the appropriate port for SSL on your router to access farmOS using https://your_domain_name:port_number. Usually port 443 but you can change it in the docker-compose.yml by changing 443:443 to new_port_number:443 eg. 1443:443 .

Facebook Comments