Do you want to build a home security system? ZoneMinder is the perfect tool to have to control the cameras.
As I know some of you are interested in this kind of project, I looked for a solution, and have found that ZoneMinder is a pretty good tool for this.
But the installation is not straightforward, so I’ll explain everything here.
How to install ZoneMinder on Raspberry Pi?
The ZoneMinder package is available in the Raspberry Pi OS default repositories, so it can be installed with apt.
It requires many dependencies, so you also need to install and configure Apache, MySQL and your cameras separately.
After a short presentation of the project, I will show you how to install the server part on your Raspberry Pi, and how to configure a camera (or more) in the web interface.
What is ZoneMinder?
As I told you in introduction, ZoneMinder is an open-source CCTV solution.
So typically, you can use it for home security, baby monitoring or many other things with cameras.
It’s a totally free solution, that you install on your systems, so you keep control on your data. That’s the main difference with other solutions, that are cloud based in general.
- Web interface: easy to access from any device (compatible with mobile), and you can access it from outside your network with port forwarding or a VPN server.
- Smartphone apps: smartphone apps are also available (I think they are not free, I didn’t test).
- Compatible with any USB or IP camera: I will speak about the Raspberry Pi camera module later, but any IP camera from the market will work with ZoneMinder.
- Third-Party integrations: many add-ons are available to interact with ZoneMinder. A detailed list in available on the official Wiki.
Compatibility with Raspberry Pi
ZoneMinder is not officially developed for the Raspberry Pi, but the source code is available and a package is present in the default repository, so there is no compatibility problem.
As I explain at the end of this post, you can probably use the camera module directly in ZoneMinder, but I didn’t find the solution quickly, so I have a workaround detailed in this post.
Also, any old webcam you have with a USB port can be easily recycled as a network camera with a Raspberry Pi.
Install ZoneMinder on Raspberry Pi
ZoneMinder is available in the Raspberry Pi repository, so we can expect an easy installation, right? Not really 🙂
ZoneMinder requires a web server and a database server, that you need to install and configure before using it.
The package will come with the clients packages, but the server has to be done separately.
Let’s see how to install everything!
You don’t need many things to start this project, but here is the stuff I have to experiment this (with links to Amazon if needed):
- A Raspberry Pi 4 and a Raspberry Pi 3B+: I will use two cameras plugged on a Raspberry Pi. The Raspberry Pi 4 hosts the ZoneMinder service.
- Two cameras module: I have an official camera module and a night-vision one:
- Raspberry Pi OS: I’m using Raspberry Pi OS Desktop, but the lite version is OK as I’m doing everything from SSH, or Secure Shell Protocol, is a cryptographic network protocol used for securely accessing and... & Web.
Check my tutorial on how to install Raspberry Pi OS if needed.
Also, I don’t have one yet, but I think a touch screen monitor could be a good add-on to this project if you want to keep it running all time.
The official touch screen display and a screen case should be perfect on your desktop or bookshelf for example 🙂
Install Apache and MariaDB
We’ll start by installing the servers.
For the web server, you can install Apache or Nginx. I chose to go with Apache, that I know better, so I’ll show you how to do this.
For the MySQL Server, it’s now MariaDB on Debian and Raspberry Pi OS.
Install the following packages:
sudo apt update
sudo apt install apache2 mariadb-server apt-transport-https
Confirm the installation by pressing “Y” when apt asks for it.
That’s it, now we need to configure it.
Create your MariaDB user
By default, on MariaDB the root user can connect without any password.
But to do this correctly, we’ll create a new specific username for ZoneMinder:
- Connect with root:
- Create a new database for ZoneMinder. I recommend naming it “zm” as the script we’ll run later also use this name
CREATE DATABASE zm;
- Then, create a new user for ZoneMinder:
CREATE USER 'zoneminder'@'localhost' IDENTIFIED BY '<password>';Don’t forget to change the password in this command.
- Almost done, just add all privileges to this user for the ZoneMinder database:
GRANT ALL PRIVILEGES ON zm.* TO 'zoneminder'@'localhost';I don’t think everything is required, but to be sure we’ll not do too much security here.
- Finally, just reload the permissions with the command:
That’s it, user created and database ready to use.
If you want, you can test the connection with:
sudo mysql -uzoneminder -p
Edit ZoneMinder configuration
We can now add this user in ZoneMinder configuration:
- If not already installed, try by installing ZoneMinder with apt:
sudo apt install zoneminderIt will automatically add all the required dependencies.
- Open the configuration file with Nano:
sudo nano /etc/zm/zm.conf
- Find and edit the following lines:
#ZoneMinder database type: so far only mysql is supported ZM_DB_TYPE=mysql #ZoneMinder database hostname or ip address and optionally port or unix socket #Acceptable formats include hostname[:port], ip_address[:port], or localhost:unix_socket ZM_DB_HOST=localhost #ZoneMinder database name ZM_DB_NAME=zm #ZoneMinder database user ZM_DB_USER=zoneminder #ZoneMinder database password ZM_DB_PASS=<yourpassword>
In theory, the only change is probably the password.
Also, you need to fix the permissions on the configuration file like this:
sudo chgrp -c www-data /etc/zm/zm.conf
Initialize the ZoneMinder database
The last step with the database is to create all tables in the database:
sudo mysql -uzoneminder -p<yourpassword> zm < /usr/share/zoneminder/db/zm_create.sql
It should be ok with the MySQL part now.
Next step is the Apache configuration, it’s much more straightforward 🙂
- Enable the ZoneMinder configuration for Apache
sudo a2enconf zoneminder
- Enable the CGI module
sudo a2enmod cgi
- Reload Apache
sudo service apache2 reload
That’s almost done, there is a quick fix I’ll give you later, but Apache is ready!
You should now be able to start the service for ZoneMinder:
- Enable the service on boot:
sudo update-rc.d zoneminder enable
- Start it now:
sudo service zoneminder start
- Check the current status:
sudo service zoneminder status
If everything is properly configured, it should be enabled.
If not, errors are displayed here.
You’ll not be able to access the ZoneMinder interface if you didn’t set the time zone correctly on your Raspberry Pi and PHP configurations.
I got this error the first time I tried:
ZoneMinder is not installed properly: php's date.timezone is not set to a valid timezone
Here is what I have done to fix it:
- Run Raspi-config to fix the system time zone if needed:
- Then go into Localization > Change Time Zone
- Select the correct time zone and remember it for the next steps
- Exit Raspi-config
Then, you can add it in your PHP configuration:
- Open the PHP configuration for Apache:
sudo nano /etc/php/7.3/apache2/php.iniThe path may change depending on the PHP version you have
- Find this line:
- And change it for example with:
date.timezone = Europe/Paris
Use the same as in raspi-config.
Don’t forget to remove the “;” at the beginning.
- Restart Apache to apply changes:
sudo service apache2 restart
It should be ok now. In any case, it fixed this for me.
Check the HTTP access
ZoneMinder is finally available with a web access.
The URL should be something like this:
We can now move to the next part and add your cameras in the interface
Before going further, I want to give you a few extra information about the installation part.
ZoneMinder has a pretty good documentation for the product (that you can find here). There is nothing for the Raspberry Pi, but I almost followed the Debian tutorial to install it on Raspberry Pi, and it works.
They also have a forum and a Slack support channel if you need any help about this part.
Also, there are Docker images available in this documentation if you are interested.
I’m not a big fan of Docker, so I didn’t try it, but If you want here is the link to the installation guide.
Add Cameras to ZoneMinder
Ok, so ZoneMinder is installed, cool. But we don’t have any camera yet in the interface 🙂
Let’s see how it works, and we’ll add some in the next part.
ZoneMinder doesn’t seem to handle the Raspberry Pi Camera locally (or at least I didn’t manage to make it work, there is probably a workaround).
So, you have at least two options to add new cameras:
- Create a network stream with your Raspberry Pi Camera Module (available on Amazon) and use it in the configuration
- Use an IP Camera from the market. I know that Nest has pretty good products for example (check this one on Amazon for example), but you can really use any IP camera (basic cameras are way cheaper).
In my example, I’ll show you how to do this with Raspberry Pi cameras, but it’s even easier with classic IP cameras.
In the ZoneMinder Console
Just before installing the camera, here is how the interface works.
For now, when you access the web interface, there is nothing in it.
You will need to add at least one camera.
You can click on the ADD button to do this, and a form will show up with all the options you can configure for this camera.
ZoneMinder calls a camera a monitor, and you can configure many things as:
- General: Monitor name, server, storage group, source type, etc.
- Source: Depending on the source type, the path or URL, the image size and orientation, etc.
- Storage: In which format you want to save the files.
- Timestamp: the timestamp format and position on the picture.
- Buffers: stream customization.
- Misc: what to do when there is an event recorded.
If you are looking for exclusive tutorials, I post a new course each month, available for premium members only. Join the community to get access to all of them right now!
Configure the Raspberry Pi Camera Module for ZoneMinder
I’ll now show you how to install a Raspberry Pi Camera Module, and add it in ZoneMinder.
If you have an IP camera, you can jump directly to the last step.
Install your camera
Start by connecting your camera to the Raspberry Pi if not already done, the connector is near the HDMI or Micro-HDMI port:
Then you need to enable the interface in raspi-config:
Go to “Interfacing options” > “Camera” and enable it.
Exit raspi-config and reboot the Raspberry Pi.
After the reboot, you can check that the camera is working with:
raspistill -o image.jpg
A file is created in your current folder that you can open to check that everything is good (on the Desktop version, the image shows up on your screen).
If you have any issue with this, please check my tutorial on how to install a camera on Raspberry Pi, this is not the point of this post.
The next step is to install Motion. Motion is a service you can run on Raspberry Pi to create a network stream with your Raspberry Pi camera module.
That’s exactly what we need for ZoneMinder, and it’s not so complicated, so it was my strategy to have two network streams for my cameras:
- Install Motion:
sudo apt -y install motion libavcodec-dev libavformat-dev libavutil-dev libjpeg-dev libjpeg62-turbo-dev libpq-dev libswresample-dev
- Enable the camera driver:
sudo modprobe bcm2835-v4l2
- Get the camera information:
This might be useful to configure ZoneMinder.
- Download the sample configuration for Raspberry Pi, and extract it:
tar -zxvf motion-mmal-lowflyerUK-20151114.tar.gz
- Start motion:
sudo motion -c motion-mmalcam-both.conf
You can start it in a screen or on boot if you want it to run all the time.
Screen is explained here, and this tutorial shows you how to start a program on boot.
Check the video stream
Once Motion is running, just check that the camera is accessible directly in your web browser.
By default, it should be something like:
If everything is good, move to the next step.
If not, you can stop motion (use CTRL+C) and edit the configuration to fix what is wrong.
Add the camera on ZoneMinder
Now that the video stream is available, you can go back in ZoneMinder and add your monitor:
- Open the web interface:
- Click on the “Add” button
- The form I explained you previously shows up
- The only thing you need to change is the source tab.
Select HTTP Tunnel as the source type and fill the URL with the video stream address.
- Change anything you want in the configuration and save.
For example, one of my camera was flipped, so I chose “Inverted” in the Source tab for Orientation.
That’s it, a few seconds later your camera should appear in the list in “Capturing” mode.
By clicking on “Montage” in the main menu, you can have a complete overview of your camera images.
Too Many Connections
After staying on the screen maybe 10-15 minutes, I got an error like this one:
Unable to connect to ZM db.SQLSTATE[HY000]  Too many connections
I don’t know exactly why, maybe there is a problem with my configuration (100 simultaneous connections is high for two cameras!).
But I fixed it by increasing the maximum connections in MySQL:
- Open the configuration file for MariaDB server:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
- Find this line:
max_connections = 100
- Replace with:
max_connections = 1000
If there is a # at the beginning of the line, remove it
- Save and exit (CTRL+O, CTRL+X)
- Restart MariaDB:
sudo service mariadb restart
Refresh the page with ZoneMinder, should be ok now.
Well done, it was a not so simple tutorial to follow I think but if you are here, it’s a success 🙂
You made the good choice, keeping control of your data and know how the system works is essential nowadays.
This installation mix a few notions I already explored on the website, so feel free to check this related posts if you need more information: