How to Install ZoneMinder on the Raspberry Pi?

ZoneMinder is an open source CCTV and IP camera management software that allows you to monitor your cameras and record video footage when motion or events are detected. In this guide, we’ll walk through how to install ZoneMinder on a Raspberry Pi.

How to Install ZoneMinder on the Raspberry Pi?

Running ZoneMinder on a Raspberry Pi provides a low cost, low power home CCTV system. We’ll cover:

  • Installing dependencies
  • Configuring the ZoneMinder repository
  • Installing ZoneMinder
  • Optimizing performance
  • Hardening the system security

By the end, you’ll have ZoneMinder running smoothly on your Raspberry Pi and viewable from any web browser on your network.

Installing Dependencies

ZoneMinder depends on a variety of packages to handle video processing, streaming and handling images from IP cameras. We need to install these before installing the ZoneMinder software itself.

Log in to the Raspberry Pi and open the terminal. Update the package manager and install the required packages:

sudo apt update

sudo apt install libapache2-mod-php7.3 php7.3-mysql mariadb-server libperl5.28 php-pear php7.3-dev php7.3-xml php7.3-json php7.3-cgi

This will install all required PHP modules, MySQL database, and other ZoneMinder dependencies.

Some additional packages are also useful for enhancing ZoneMinder’s functionality:

sudo apt install libav-tools

We also need to make sure Apache can handle large video streaming requests:

sudo nano /etc/php/7.3/apache2/php.ini

Find the memory_limit line and set it to:

memory_limit = 1024M

Save and close the file.

Configuring the ZoneMinder Repository

While ZoneMinder is available in the standard Raspbian repository, that version is often behind the latest by quite some margin. We’ll add the ZoneMinder repository directly to install the newest stable version.

First install the tool to securely add new repositories:

sudo apt install lsb-release gnupg

Add the GPG key for the ZoneMinder repository:

wget -q -O – https://zmrepo.zoneminder.com/debian/zmrepo.gpg.key | sudo apt-key add –

Next, add the repository:

echo “deb https://zmrepo.zoneminder.com/debian/$(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/zmrepo.list

The ZoneMinder repository is now configured. Update apt again:

sudo apt update

Installing ZoneMinder

With all dependencies installed and repository configured, we can now install the ZoneMinder package itself:

sudo apt install ZoneMinder

Accept any prompts during the installation process.

Once installed, run the post-installation script. This optimizes some system settings for better ZoneMinder performance:

sudo /usr/share/zoneminder/postinstall/postinstall.sh

ZoneMinder is now installed, but there are some additional settings to address before it’s ready for use.

Optimizing Performance

Running ZoneMinder on the Raspberry Pi’s more limited CPU and memory requires some optimization for the best performance.

Memory Split

By default, the full memory of the Raspberry Pi is allocated to GPU functions. This leaves very little for ZoneMinder recording streams from multiple cameras.

We need to re-allocate some memory to the CPU processes instead.

sudo raspi-config

Select “Advanced Options” then “Memory Split” Change the split to 256. This dedicates 256MB to the CPU which is ample for streaming multiple HD cameras in ZoneMinder.

You’ll need to reboot for memory split changes to take effect:

sudo reboot

Once your Pi has restarted, log back in and continue with optimizing ZoneMinder.

MySQL Configuration

ZoneMinder uses the MySQL database to record event details, camera status, etc. Some default MySQL settings like tmp_table_size and max_heap_table_size are too low for reliable ZoneMinder use.

Edit the mysql config:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Within the [mysqld] section add the following and save + close:

tmp_table_size=512M

max_heap_table_size=512M

Restart mysql for this to take effect:

sudo systemctl restart mysql

ZoneMinder Configuration

Lastly, we need to enable a couple settings in the ZoneMinder server configuration itself.

Edit the ZoneMinder config file:

sudo nano /etc/zm/zm.conf

Find the following lines and change them to:

OPT_FFMPEG_DEFAULTS = ‘-threads 2’  

OPT_CAMBOZOLA_DEFAULTS = ‘-threads 2’

This instructs ZoneMinder to only use 2 threads for video processing rather than trying to use multiple and overload the limited Raspberry Pi CPU.

While editing this file, also find:

ZM_WEB_THREADS = ‘4’

And reduce it to:

ZM_WEB_THREADS = ‘2’

To reduce apache threads as well.

Save the file and exit. Finally, restart ZoneMinder:

sudo systemctl restart zoneminder.service

ZoneMinder is now optimized for best performance on the Raspberry Pi platform!

Hardening System Security

Since ZoneMinder can record sensitive security footage and access cameras, it’s important to harden the Pi itself against unwanted access.

Here are some best practices:

User Access

  • Disable password login for root user
  • Create a separate ZoneMinder admin account
  • Use SSH keys instead of passwords

Network Security

  • Change default admin login from zmuser/zmuser if exposing admin controls externally
  • Limit access to ZoneMinder admin console
  • Make sure all software is kept up to date

Data Encryption

  • Encrypt saved media files
  • Automated backups to encrypt cloud storage

With some prudent security steps, you can comfortably run ZoneMinder without risking footage or camera access.

Conclusion

Installing ZoneMinder on a Raspberry Pi takes more initial configuration than pre-built NVR appliances, but provides far more power and customization for home CCTV projects.

By installing dependencies, configuring the repository, optimizing performance, and hardening security, you’ll have a robust CCTV system tailored to your needs at a fraction of the cost.

Now you can add cameras, configure zones and events for motion detection & recording, and monitor all footage easily through the web console anywhere on your network!

Frequently Asked Questions

  1. How do I access the ZoneMinder web admin interface?
    Navigate to the IP address of your Pi on port 8080 in any browser. So for example http://192.168.1.102:8080.

  2. Can the admin console be accessed externally?
    Yes! Port forward 8080 and set the ZoneMinder Options to allow remote access. We recommend using VPN for external access from mobile devices or outside your home network.

  3. What resolution/framerate cameras work well?
    720p or 1080p at 15fps is a good target for the Pi hardware. You can also reduce the analysis framerate under Events to reduce CPU load.

  4. Can I encrypt the media files?
    Absolutely, ZoneMinder integrates with ZM-Crypt to encrypt all stored and recorded media for privacy.

  5. Does ZoneMinder integrate with Home Assistant or other home automation?
    Yes, there are official and community integrations to tie events into most automation platforms. Check the ZoneMinder wiki for details.

  6. How many cameras can a Pi handle?
    Between 3-8 cameras is realistic depending on resolution and event settings. An Intel NUC or more powerful hardware can manage 20+ camera feeds.

  7. Can I view the cameras from my phone?
    Yep! The web admin works on mobile, or you can use the ZoneMinder mobile apps for iOS and Android.

  8. What length of video footage can be stored?
    This comes down to the size of your SD card or external USB drive plugged into the Pi. With optimizations, a 128GB card can store a few weeks of 24/7 recordings for 4 cameras depending on FPS and resolution.

  9. Is there a web app for live monitoring?
    Yes there is an official ZoneMinder web app as well as several community projects like zmNinja.

  10. Can ZoneMinder integrate with my other smart home devices?
    Absolutely! Check the ZoneMinder wiki for tutorials using the Event Server with automation platforms like Home Assistant. Lots of possibilities to trigger lights, alarms and other actions!

  11. Which Raspberry Pi models does ZoneMinder support?
    Any Pi from the Pi 3 B+ and up has enough CPU and memory to run ZoneMinder well. The Pi 4 has plenty of headroom for additional cameras and functionality.

  12. How do I monitor activity when not home?
    You’ll want to set up port forwarding and Dynamic DNS for remote access from your mobile device or computer. A VPN provides the most secure method of tapping into the ZoneMinder console anywhere.

  13. Can I set an upload to backup important footage?
    Yes, ZoneMinder can integrate with cloud services to automatically back up event triggered clips or the entire 24/7 stream to encrypted storage via plugins.

  14. Does ZoneMinder work with webcams or only IP cameras?
    ZoneMinder works with pretty much any camera source that can provide an RTSP stream! So webcams via webcamd, NAS cameras, IP cameras and more are all options for video sources.

  15. Can motion zones be set to only record part of the camera view?
    Absolutely! One of the most powerful ZoneMinder features is creating custom zones within the field of view for motion detection, that way leaves blowing doesn’t trigger video outside your area of interest.

  16. Is there a ZoneMinder mobile app?
    Yes, ZoneMinder recently released official iOS and Android apps for mobile access. There are also several well supported community mobile apps like zmNinja.

  17. How difficult is the ZoneMinder learning curve?
    The initial installation can be quite involved depending on camera models and networking setup. Thankfully the documentation is excellent, and the community very active for help getting up and running. Basic functions are quite user friendly.

  18. What advantages does ZoneMinder offer over commercial NVR systems?
    Much more customization – you can tweak ZoneMinder to perfectly suit your cameras, retention needs, motion detection preferences etc. It’s also completely free and open source!

  19. What resolution should I set for my cameras?
    720p or 1080p is a good target. The higher the resolution, the more taxing on your Raspberry Pi’s CPU. You can lower analysis resolution in ZoneMinder while keeping high res recordings as a balanced tradeoff.

  20. Which Raspberry Pi OS should I use?
    The standard 32-bit Raspberry Pi OS works perfectly. The 64-bit OS also works well if your Pi supports it. Ubuntu Server also works fine in place of Raspberry Pi OS.

Leave a Comment