Pi ZoneMinder NVR

Open source video surveillance software system

Board version: Pi 5 B Rev 1.0
Memory: 8 GB
RPi OS version: Lite 32-bit
Site: https://zoneminder.com/
Recommended: Raspberry Pi Active Cooler for RPi 5
M.2 NVMe SSD (2230/2242/2260/2280) - Samsung 960 EVO 250 GB
M.2 NVMe HAT: https://wiki.geekworm.com/X1001



Basic installation OS


Install and Prepare the Database

We need also to install a database. A good choice for Raspberry PI, compatible with ZoneMinder, is MariaDB. Nevertheless, the main commands are the following: $ sudo apt install mariadb-server Reboot


After installing the database server, you should run the MySQL secure installation script. This script helps remove weak security settings from the database server: $ sudo mysql_secure_installation

  1. When prompted to enter the password for the root user, leave it blank and press the ENTER key.
  2. Since the root user is configured by default to use unix_socket authentication. Type in n then press the ENTER key.
  3. You will then be prompted to change the root password. Since unix_socket is being used, type n then press ENTER.
  4. For the rest of the options you are presented with, type in Y, then press the ENTER key. The rest of the options will improve the security of your database server.


Create the database with related user, and assign the proper permissions with the following terminal commands (copy-paste line by line). Please change the user name and user password with your preferred ones. $ sudo su $ mariadb CREATE DATABASE zm; CREATE USER '[zoneminder_usr]'@'localhost' IDENTIFIED BY '[password]'; GRANT ALL ON zm.* TO [zoneminder_usr]@localhost; FLUSH PRIVILEGES; exit; $ exit Please note that the database name (“zm”) is linked in the following DB preparation script from ZoneMinder. If you want to change the name, you will have to edit the default database configuration script by using the new name.

Reboot


Install ZoneMinder

To be able to install ZoneMinder from the official repository to our Raspberry Pi we need to first save the GPG key. The advantage of using the official repository is that you will get the latest release. You can save and store the GPG key to your system by using the following command below within the terminal: curl -L https://zmrepo.zoneminder.com/debian/archive-keyring.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/zoneminder-archive-keyring.gpg >/dev/null
With the GPG key saved, we can proceed to add the ZoneMinder repository to the sources list. To add this repository, use the command below within the terminal: echo "deb [signed-by=/usr/share/keyrings/zoneminder-archive-keyring.gpg] https://zmrepo.zoneminder.com/debian/master $(lsb_release -cs)/" | sudo tee /etc/apt/sources.list.d/zoneminder.list
Since we have made changes to our sources, we will need to perform an update of the package list cache. You can update that cache by using the following command: $ sudo apt update
With the repository added, you can now install ZoneMinder to your Raspberry Pi by using the following command: $ sudo apt install zoneminder Reboot


Now we must prepare the database configuration for ZoneMinder. The software brings a ready-to-use SQL script that makes all the job for us.
So, we can perform all the database configurations with this single line command, where [zoneminder_usr] and [password] must be changed with the ones set a few lines before. Please note that the password is attached with the -p option: $ mariadb -u [zoneminder_usr] -p[password] < /usr/share/zoneminder/db/zm_create.sql This script will create all the required database structures, setting up the required tables with the needed columns and charsets.


Tweak Zoneminder configuration for Raspberry Pi

With the following terminal commands, copy-paste line by line: $ sudo apt install php libapache2-mod-php php-mysql $ sudo chmod 740 /etc/zm/zm.conf $ sudo chown root:www-data /etc/zm/zm.conf $ sudo chown -R www-data:www-data /var/cache/zoneminder/ $ sudo adduser www-data video $ sudo a2enmod cgi $ sudo a2enmod rewrite $ sudo a2enconf zoneminder $ sudo systemctl reload apache2.service $ sudo systemctl enable zoneminder.service $ sudo systemctl start zoneminder.service Reboot

At this point, you should have your zoneminder.service correctly running, check it with the systemctl status command: $ sudo systemctl status zoneminder.service


Correcting your Raspberry Pi’s Timezone

Our next step is to modify the PHP timezone by adjusting the configuration files. Since the default version of PHP can change depending on the OS, we can grab the version number by using the following line: $ PHP_VERSION=$(php -v | head -n 1 | tail -n 1 | cut -d " " -f 2 | cut -c 1-3) Now that we have the PHP version stored in an environment variable, we can easily edit the correct configuration file. Begin modifying PHP’s configuration file by using the following command: $ sudo nano /etc/php/$PHP_VERSION/apache2/php.ini Within this file, you will want to find the following line. Since we are using the nano text editor, you can search using CTRL + W: ;date.timezone = For example, we would use the following line to set the time zone to Amsterdam, Europe.
Replace with: date.timezone = Europe/Amsterdam Once done, you can save and quit by pressing CTRL + X, followed by Y, then the ENTER key.

Reboot


Connect Zoneminder Web UI

Now, your ZoneMinder service should be up and running. You can reach it by using the Raspberry Pi's IP Address with the “/zm” trailing as URL in your favourite browser. For example, as my RPI has internal IP 192.168.1.178, the complete URL will be http://192.168.1.178/zm. http://[YOUR-IP-ADDRESS]/zm


IP Network PoE Cameras for Zoneminder

Generally speaking, any camera that is ONVIF compliant will work with ZoneMinder.