FotoKruse

Photography as a hobby

Dec 05 2022

How to install Piwigo on a Raspberry Pi 4?

Piwigo
Pencil icon to edit the post Modified on 22 April 2023

1. Introduction

This article describes how to install Piwigo on a Raspberry Pi 4 configured as a web server. Piwigo is an open source photo management software to manage, organize and share your photo easily on the web. Your images can be viewed and managed from a common web browser or from Piwigo mobile applications available for Android and Apple devices.

So far I have been using the hosting company Antagonist in The Netherlands, which provided the required services in my case very well as I have still an old contract allowing me to use as much storage space as I need, while newe contracts limit the amount of storage space. The service, speed and functionality provided by Antagonist is outstanding.

So why setup my own web server with Piwigo? Although I have unlimited storage space at Antagonist the CPU and RAM available is limited. If I add more and more sites it becomes slow, hence I want to have my own web server for time being next to hosting some at Antagonist.

We will first explain how to configure the Raspberry Pi 4 as a web server and in next chapter how to install Piwigo.

2. Requirements

The following is required:

  • a Raspberry Pi 4 model B with Raspberry Pi 4 OS Desktop installed
    (in our case a Raspberry Pi 4 model B with 8 Gb RAM and a 500 Gb Samsung sata SSD in a Geekworm NASPi 2.0 case.
  • Terminal editor within Raspberry Pi 4 OS Desktop (installed by default)
  • To be installed:

3. Configure a Raspberry Pi 4 as web server

To configure the Raspberry PI OS Desktop (from now onwards referred to as RP4 desktop) the Terminal application will be used. Open the Terminal from the RP4 desktop by clicking on the terminal button.

Tip: Commands used in this article can be copied and pasted in the Terminal (use right mouse button in the terminal and select paste. Press enter to execute the command(s).

3.1 Assure the Raspberry Pi 4 OS is up to date

Before we configure the RP4 as web server we check the OS is up to date by entering the following command in the Terminal and press enter:

sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y

The update command checks if there are updates available and if so will download them, while the upgrade command will install the updates. The autoremove will remove not required installed packages automatically. All the three commands have been combined in one line by using &&.

3.2 Install the web server (Apache)

We choose Apache, a well known fast web server providing advanced functionalities to expose web pages. To install it enter the following command in the Terminal.

sudo apt install apache2 -y

Wait till the commands have been executed and test the Apache web server is working by entering the IP address of your Raspberry Pi 4 in a browser.  In my case I entered 192.168.1.51, which gets converted in the browser to http://192.168.1.51/. A similar screen as below should be displayed.

Apache 2 start page

3.3 Add the required PHP modules/packages to the webserver

Piwigo requires several modules/packages to be available on the web server.

  • imagick
  • gd
  • ffmpeg
  • mbstring (required for Debian)
  • XML (required for Debian)
  • exif: already included in php-common

These can be installed by entering the next command in the Terminal.

sudo apt install php-imagick php-gd ffmpeg php-mbstring php-xml -y

Wait till the installation has been completed. Currently the PHP version installed will be PHP version 7.4 and not version 8.x. This is fine for the time being.

3.4 Install the database environment

We will install MariaDB database environment instead of MySQL. MariaDB is a fork of MySQL,  but  uses less resources. We’ll install it together with the PHP connector so that MariaDB and PHP will be already able to communicate.

  1. Enter the following command in the Terminal:
    sudo apt install mariadb-server php-mysql -y
  2. Wait till the installation has been completed. Enter the next command to start the procedure to secure the database environment.
    sudo mysql_secure_installation

    The following screen will be displayed in the Terminal.
    Raspberry Pi 4 - Securing MariaDB database environment

  3. Answer the questions as listed in the steps below:
    1. As no password has been set yet press enter.
    2. Switch to unix_socket authentication [Y/n] –> n
    3. Change the root password? [Y/n] –> Y
    4. New password: –> type your new root password
      Make sure you remember/store is for example with the Keepass password manager.
    5. Re-enter new password: –> type again your new root password
    6. Remove anonymous users? [Y/n] –> Y
      Info displayed in Terminal window: By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
    7. Disallow root login remotely? [Y/n] –> Y
      Info displayed in Terminal window: Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network.
    8. Remove test database and access to it? [Y/n] –> Y
      Info displayed in Terminal window: By default, MariaDB comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
    9. Reload privilege tables now? [Y/n] –> Y
      Info displayed in Terminal window: Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
  4. To make it easier to manage the databases we install also phpMyAdmin via the following Terminal command:
    sudo apt install phpmyadmin -y

    After the installation is completed the following screen will be displayed inside the Terminal:

  5. In the phpmyadmin setup screens make the following settings:
    1. Select apache2 with space (a * will be displayed in the red field) and use the tab key to move to <OK> and press enter when it is selected (red color). The installation will continue now.
    2. select Yes by pressing enter key to configure the database for phpmyadmin with dbconfig-common.
    3. In next screen enter a login password for the user phpmyadmin, which is required to login phpMyAdmin later. DO NOT USE the option to generate a random password!
      Re-enter the password to confirm. The installation will continue. Wait till it is finished.
  6. Grant phpMyAdmin user rights to manage the databases:
    1. Connect to MariaDB with root user (default password is one before set)
      sudo mysql -uroot -p

      Enter the root user password given during installing MariaDB. You will be logged in into the MariaDB monitor.

    2. Grant permissions by entering the following commands after each other:
      grant all privileges on *.* to 'phpmyadmin'@'localhost';
      flush privileges;
      quit
  7. Reboot the Raspberry Pi 4 by entering the command
    sudo reboot
  8. Check phpMyAdmin has been installed correctly by using your web browser to access phpMyAdmin via the Raspberry PI’s IP address followed by “/phpmyadmin/” (for example http://192.168.1.51/phpmyadmin/). The login screen will be displayed.
  9. Enter “phpmyadmin” as username and the earlier provided password.
  10. If it works you can close the browser page.

4. Install Piwigo

Before Piwigo is installed the database needs to be setup. In my situation I am setting up a development environment for Piwigo which will be used to convert my existing Piwigo template for version 11.5 (as used on gallery.fotokruse.eu) to Piwigo version 13.x.y

      1. Setup the database in MariaDB
      2. Install Piwigo

4.1 Setup the database

  1. Log into MariaDB as root user by entering the following command in the Terminal:
    sudo mariadb -u root
  2. Create a database for Piwigo. In my case I use the database name “piwigo_13_dev”, but you can name it as you prefer:
    create database piwigo_13_dev;
  3. Grant all privileges of the Piwigo database to the user (with password) that you will configure in Piwigo in the next steps. Please replace:
    1. PIWIGO by your database name
    2. PIWIGO_USER by your prefered piwigo database user name
    3. PIWIGO_DATABASE_PASSWORD by your piwigo database user password
      grant all privileges on PIWIGO.* to PIWIGO_USER@localhost identified by 'PIWIGO_DATABASE_PASSWORD';

      In my case I used:

      grant all privileges on piwigo_13_dev.* to piwigo_13_dev_user@localhost identified by '********';
  4. Flush the privileges table for the changes to take effect and then exit
    flush privileges;
    exit;

TEST

sudo mariadb

CREATE DATABASE piwigo;
CREATE USER piwigo IDENTIFIED BY ‘supertopsecretpassword’;
GRANT USAGE ON *.* TO piwigo@localhost IDENTIFIED BY ‘supertopsecretpassword’;
GRANT ALL privileges ON piwigo.* TO piwigo@localhost;
FLUSH PRIVILEGES;
quit;

4.2 Install Piwigo

We use the manual method to install Piwigo.

  1. Download the installation package directly in your Raspberry PI and uncompress it:
    curl http://piwigo.org/download/dlcounter.php?code=latest -o piwigo.zip
    unzip piwigo.zip
  2. The content of the folder with the unzipped Piwigo files must now be moved into the Apache public folder. Replace the “PIWIGO” folder by the name (lowercase) you prefer, remembering to use your folder name both on the URL and in the following commands:
    sudo mkdir /var/www/html/PIWIGO
    sudo mv piwigo/{.,}* /var/www/html/PIWIGO/

    In my case I used

    sudo mkdir /var/www/html/piwigo13dev
    sudo mv piwigo/{.,}* /var/www/html/piwigo13dev/

    The move command mv will give warnings that can be neglected; device or resource busy, cannot move … etc. Reason is that with the “{.,}” part we moved also the hidden files and with this trick the mv command tries also to move the current folder (“.”) and the parent folder (“..”), but it doesn’t perform the move of the two.

  3.  Assign the correct privileges to the public folder in order to make it possible for Piwigo installer to do its tasks:
    sudo chown -R www-data:www-data /var/www/html/
  4. Remove the folder used to unzip the piwigo files:
    rmdir piwigo/
  5. We use now the browser to complete the installation steps. Enter as URL your Raspberry PI’s IP address followed by the “piwigo” folder name used in step 2. So in my case it becomes
    http://192.168.1.51/piwigo13dev
    The Piwigo installation page will be shown.
  6. Add your database name, database user and database user password. Leave the Host variable set to “localhost”.
  7. Choose the piwigo administrator username, password and email address. These will be the ones you use to access the web dashboard. In my case I entered the following:
  8. Click on “Start installation”.

 

https://www.makeuseof.com/install-use-piwigo-raspberry-pi/

https://linuxhint.com/install-piwigo-raspberry-pi/

Piwigo and Raspberry PI: a Private Open Source Photo Management Platform

https://peterries.net/blog/piwigo-on-raspberry-pi/

 

 

Leave a Reply