Posted on 3 Comments

LXD Dashboard – Installing from source in Alpine Linux

Launching an LXC based Alpine container

This how-to guide will take you through the installation steps to run the LXD dashboard in an LXC container on your system. This guide will assume that your system already has LXD installed and configured.

Start by launching a new instance using the Alpine 3.14 image. To launch the new instance and name it lxd-dashboard use the following command:

lxc launch images:alpine/3.14 lxd-dashboard

This will create a base container to use to install the LXD dashboard. Once the command finishes the container should be running. Now it is time to connect into the container and setup the software. Use the following command to obtain a shell connection to the instance, use the exit command at anytime to leave the shell:

lxc exec lxd-dashboard /bin/sh

Install Nginx and PHP

The following commands will now be run inside the lxd-dashboard container. The installation guide uses Nginx and PHP for the webserver platform and SQLite as a database. To install these packages use the following command:

apk update && apk add nginx php php-fpm php-curl sqlite php-sqlite3 php7-session php7-pdo php7-pdo_sqlite php7-json php7-openssl 

Setting up the LXD Dashboard

Using wget, the source code for the LXD dashboard can be downloaded from the GitHub repository. For this guide the v3.4.0 release will be used. Check for newer versions on the GitHub page and replace the version number with the latest. To download and extract the source code use the following two commands:

wget https://github.com/lxdware/lxd-dashboard/archive/v3.4.0.tar.gz
tar -xzf v3.4.0.tar.gz

A few web server files will need to moved into place for the web pages as well as the NGINX configuration. To copy these files use the following commands, making sure to change the version number to what was downloaded:

cp -a lxd-dashboard-3.4.0/default /etc/nginx/http.d/default.conf
mkdir -p /www
cp -a lxd-dashboard-3.4.0/lxd-dashboard /www/

The default.conf file used for Nginx needs slighly modified to work in Alpine Linux.

vi /etc/nginx/http.d/default.conf

Modify the default.conf file to read as follows, paying close attention to the text in red:

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	root /www/lxd-dashboard;
	index index.php index.html;
	server_name _;

	location / {
		try_files $uri $uri/ =404;
	}
	
	location ~ \.php$ {
	fastcgi_pass 127.0.0.1:9000;
    	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	include fastcgi_params;
    	include fastcgi.conf;
     }
}

The default user:group assigned to php-fpm is nobody:nobody. This will need to be changed to the user and group used by the webserver, nginx:www-data. Edit the /etc/php7/php-fpm.d/www.conf file and change the user and group assignment.

vi /etc/php7/php-fpm.d/www.conf

There are three main directories that LXDWARE uses to store persistent information for the application. You will need to create these directories and then assign appropriate ownership to the web server. To create the directories use the following commands:

mkdir -p /var/lxdware/data/sqlite
mkdir -p /var/lxdware/data/lxd
mkdir -p /var/lxdware/backups

The /www/lxd-dashboard/ directory, the /var/lxdware/ directory, and the contents within them all need to be owned by the web server user. Although the /etc/nginx/nginx.conf file lists nginx as the user, when configuring the LXD Dashboard, the nobody user was being used by the webserver. To set the proper permissions run the following commands:

chown -R nginx:www-data /var/lxdware/
chown -R nginx:www-data /www/

Starting and Enabling the Nginx and PHP services

The NGINX web server and PHP will both need to be started. To start the web server run the following commands:

service nginx start
service php-fpm7 start

To enable both services to start automatically when the server boots use the following two commands:

rc-update add nginx default
rc-update add php-fpm7 default

Congratulations! The container is now setup with the LXD dashboard software. Exit from the shell terminal and return to your LXD host server by using the command:

exit

Open a web browser and access the LXD dashboard by entering in the IP address of the instance. Use the lxc list command to view a list of the containers and their IP addresses on your LXD server.

Known Issues with Alpine

The php-fpm application in Alpine Linux is preventing the LXD Dashboard from exporting instance backups from the LXD server to the to /var/lxdware/backups/… directory.

3 thoughts on “LXD Dashboard – Installing from source in Alpine Linux

  1. Updated this guide to use the current 3.4.0 version of LXD Dashboard

  2. Hello Matthew,

    do you know, WHY there the php-fpm application in Alpine Linux prevents your *amazing* LXD Dashboard from exporting instance backups to /var/lxdware/backups – directory? I would like to fix that, I am using your LXD Dashboard in Alpine..

    keep up the great work,
    Ingo Baab

    1. Hello Ingo,
      I am not sure yet why exporting is not working for Alpine. I remember trying to see if it would working giving the directory 777 permissions, but I don’t think that worked either. I can take a look again and investigate to see what might be going on.
      Thanks,
      Matt

Leave a Reply

Your email address will not be published.