Installing LimeSurvey with Docker on Ubuntu 16.04 with Nginx and Mariadb

View recent blog entries

LimeSurvey is an open source survery tool, functionally similar to far more heavily marketed proprietary tools like SurveyMonkey and Google Forms. It's a very mature, fully-featured system. You can either use the reasonably priced hosted service available on the LimeSurvey site, or you can host your own, holding your own data and collecting your own analytics if you prefer. The only cost of hosting your own is your time to set it up and any costs associated with your hosting environment (which, today, can be negligible). Our instance is on https://survey.oeru.org...

Setup

It's as simple as having a server online somewhere (perhaps provided by your organisation or institution or if you're not sure where to go, I can recommend Digital Ocean - note: I have no affiliation with them other than being a happy customer)  and installing Docker-CE (including use by non-root users) and Docker Compose (I prefer to do this with 'pip' as described in the link).

First create Docker and Data directories on your server:

sudo mkdir /home/docker home/data
sudo chown ${USER}:${USER} /home/docker home/data

And we'll create a directory for Limesurvey's docker compose configuration and data respectively:

mkdir /home/docker/limesurvey /home/data/limesurvey

Then you simply have to create a docker-compose.yml file in /home/docker/limesurvey with your preferred editor (I use vim. If you don't know vim or vi, use nano which is easy to use and self-explanatory, e.g. nano /home/docker/limesurvey/docker-compose.yml ) containing the following:

version: '3'
services:
  lime:
    restart: unless-stopped
    image: oeru/limesurvey
    ports:
      - '127.0.0.1:8080:80'
    volumes:
      - '/home/data/limesurvey/upload:/var/www/html/upload'
      - '/home/data/limesurvey/plugins:/var/www/html/plugins'
      - '/home/data/limesurvey/config:/var/www/html/application/config'
      - '/home/data/limesurvey/reference:/var/www/reference'

Last steps, you need your domain name you want to use, and to install Nginx on your server and configure it

apt update && apt install nginx-full

and you then need to add a configuration file in /etc/nginx/sites-available/limesurvey that looks like this (let's say your domain is "survey.oeru.org" - obviously, replace with your own domain :) ):

server {
  listen 80;
  root /var/www/html;
  index index.html index.htm;
  server_name survey.oeru.org;

  ## Access and error logs.
  access_log /var/log/nginx/survey.oeru.org_access.log;
  error_log /var/log/nginx/survey.oeru.org_error.log;

#  include /etc/nginx/includes/letsencrypt.conf;

#  location / {
#     return 302 https://survey.oeru.org$request_uri;
#  }
#}

# server {
#  listen 443 ssl;
#  ssl on;
#  ssl_certificate /etc/letsencrypt/live/survey.oeru.org/fullchain.pem;
#  ssl_certificate_key /etc/letsencrypt/live/survey.oeru.org/privkey.pem;
#  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#  ssl_dhparam /etc/ssl/certs/dhparam.pem;

#  keepalive_timeout 20s;

#  root /var/www/html;
#  index index.html index.htm;

#  server_name survey.oeru.org;

#  ## Access and error logs.
#  access_log /var/log/nginx/survey.oeru.org_access.log;
#  error_log /var/log/nginx/survey.oeru.org_error.log;

  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $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-Proto $scheme;
    add_header Front-End-Https  on;
    proxy_pass http://127.0.0.1:8080;
  }
}

Note the port number 8080 - this is set in your docker-compose.yml file - it should be any free high port on your server (i.e. not already in use by another application - netstat -punta will help you work out what's in use). Change the port number to whatever you've set in the docker-compose.yml file.

You'll note that many of the lines start with a # - these are commented out, particularly the info about SSL (secure sockets layer - encrypted transmission between users' computers and your server). Use our Lets Encrypt howto to set that up - it's worth it for your users' security! Once you do that, you can remove the extra layer of # to create two server configurations - one for HTTP which redirects users to the other which implements HTTPS.

You need to "enable" your nginx configuration like this:

sudo ln -sf /etc/nginx/sites-available/limewire /etc/nginx/sites-enabled

Then you can confirm that it's set up properly by running

sudo nginx -t

and if it returns without errors, you can implement your settings with (this should work even if you've never started nginx before!):

sudo service nginx restart

You should then be able to go to your site on http://survey.oeru.org (replaced, of course, with your own domain).

Upgrades

No recipe is very useful unless it gives you an idea how to provide ongoing maintenance for your application. Limesurvey is a wee bit tricky, but not too hard. This is how we do it when you see that there's an upgrade available (check https://hub.docker.com/r/oeru/limesurvey/ to see!)

  1. make a copy of your existing plugins and configuration: sudo mkdir /home/data/limesurvey-backup && cp -a /home/data/limesurvey/config /home/data/limesurvey/plugins /home/data/limesurvey-backup
  2. go to /home/docker/limesurvey (cd /home/docker/limesurvey) and run docker-compose pull to get the most recent Docker container I've produced.
  3. prepare your users for brief downtime.
  4. run docker-compose stop to stop the current Limesurvey site
  5. move the old config and plugin directories sudo mv /home/data/limesurvey/config /home/data/limesurvey/config.old && sudo mv /home/data/limesurvey/plugins /home/data/limesurvey/plugins.old (this might overwrite previous old updates, which is hopefully ok! If not, choose something other than .old as a file suffix - perhaps the date)
  6. run docker-compose up -d This will start the new Limesurvey docker container.
  7. You can then run docker-compose exec lime cp -a /var/www/html/application/config.orig /var/www/html/plugins.orig /var/www/reference/ which is a sneaky way of running commands on the container itself. When I build the docker container you've "pulled" down, I copy the default config and plugins directories to config.orig and plugins.orig to ensure they're still there for you - this copies them somewhere on your local filesystem where you can usefully access them...
  8. You need to copy the reference configuration and plugins to the appropriate directories with sudo cp -a /home/data/limesurvey/reference/config.orig/* /home/data/limesurvey/config/ && sudo cp -a /home/data/limesurvey/reference/plugins.orig/* /home/data/limesurvey/plugins/
  9. Then you need to copy your previous config.php file to where it belongs: sudo cp /home/data/limesurvey/config.old/config.php /home/data/limesurvey/config/ and the same with any plugins you have added to your instance. The latter will require you go copy them each individually from /home/data/limesurvey/plugins.old/_____ to /home/data/limesurvey/plugins - Just be sure not to overwrite plugins provided by the updated Limesurvey!
  10. make sure all the permissions are ok: sudo chown -R www-data:${USER} /home/data/limesurvey/* && sudo chmod -R g+w /home/data/limesurvey/* which will allow both you to read and write all files and the webserver user (www-data) to read (and potentially write) the files it needs to.
  11. Finally, you need to run the database update in your browser (again, replacing with your domain name, and https if applicable): http://survey.oeru.org/admin/upgrade which should walk you through the process of upgrading. After that, you're good to go!

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.