How to setup ZoneMinder on Ubuntu 24.04 LTS


If you are new to setting up your own video surveillance system for your home or office or a customer’s home or office, and want to truly own the setup, you want to use ZoneMinder, an open-source and free software that allows you to connect a variety of wired PoE cameras to a single software server that can manage all of them.

In this post, we outline how to set it up from scratch on Ubuntu 24.04 LTS.

REQUIREMENTS

For the server that runs ZoneMinder, you will need a minimum of 8GB RAM, 2-4 Intel CPUs, and a 1 TB hard drive. You can buy a used server on eBay and upgrade it, or use an older system that can run 24/7. We recommend using a server or workstation or desktop type product, since a laptop will run too hot and eventually die too early.

Disk is cheap, so buy the largest hard drives you can afford. Spinning hard drives are sufficient. You can optimize, like we did, where we used a smaller solid state drive (SSD) for the operating system and save the data such as video files and images to the regular hard drives.

Without 8GB RAM, ZoneMinder will struggle to process more than 2-3 cameras, especially, if you are setting them up for motion detection or record on motion detection.

INSTALLATION OF UBUNTU

If you have 2 or more disk drives in your server/workstation that will run ZoneMinder, and they are all of the same type, such as all of them are SSDs or spinning hard drives, then we recommend installing Ubuntu 24.04 LTS with LVM.

LVM will allow you to add more drives in the future without having to change the way the file system is.

If you have a single drive, we still recommend installing Ubuntu 24.04 LTS with LVM so that you can add more drives in the future.

If you have two separate drives, one SSD and one a spinning hard drive, we recommend installing Ubuntu 24.04 LTS on the SSD and then setting up LVM on the spinning hard drive(s), and we will configure ZoneMinder to use those hard drives for the storage of video files.

Guides for installing Ubuntu can be found here.

INSTALLING ZoneMinder

Once you have installed Ubuntu 24.04 LTS on your system and rebooted it, you can now install ZoneMinder.

Install Apache and MariaDB

The first step is to install apache2 and mariadb from the repository. Apache2 is a web server that will host the ZoneMinder code as a web application, and MariaDB is the database that ZoneMinder will use.

You will need root access to do this, and for now we will use the sudo command.

$ sudo apt -y install apache2 mariadb-server
Setup Users in MariaDB

We then setup a database user in MariaDB so that ZoneMinder can access it.

### login as root
$ sudo su -
#### login to mariadb
root$ mariadb
#### create the database that ZoneMinder needs
mariadb> CREATE DATABASE zm;
#### create a new user zmuser and a custom password for it
mariadb> CREATE USER zmuser@localhost IDENTIFIED BY 'change_this_passw0rd';
#### grant all privileges
mariadb> GRANT ALL PRIVILEGES ON zm.* TO zmuser@localhost;
mariadb> FLUSH PRIVILEGES;
#### exit
mariadb> exit;
root$ exit

NOTE: Make sure you note down what password you chose for the zmuser account as you will need to edit a configuration file later with that password.

Install ZoneMinder

Now we install the zoneminder package from the Ubuntu 24.04 LTS repository. As of this writing the version 1.36.33 gets installed from the Ubuntu package repositories. If you need newer versions please refer to the ZoneMinder website.

$ sudo apt -y install zoneminder
$ sudo chown -R www-data:www-data /usr/share/zoneminder/www/api
Configure ZoneMinder DB Password

Now you need to configure the MariaDB password you had set above for zmuser in the /etc/zm/zm.conf file. Change the variable ZM_DB_PASS=zmpass to be ZM_DB_PASS=change_this_passw0rd or whatever password you had chosen and save it.

Configure PHP Time Zone

On Ubuntu 24.04 LTS, as of this writing, the PHP version is 8.3.

Edit /etc/php/8.3/apache2/php.ini and change the date.timezone field to point to your time zone. Our timezone is America/New_York so we set it to the below. You may have to uncomment the default UTC timezone and change it.

date.timezone = America/New_York
Configure Apache2

When you installed ZoneMinder above using apt, the file /etc/apache2/conf-available/zoneminder.conf was created as part of it.

Edit this file and make it look like this so that all functionality regarding the API and the web interface work as expected:

ScriptAlias /zm/cgi-bin "/usr/lib/zoneminder/cgi-bin"
<Directory "/usr/lib/zoneminder/cgi-bin">
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    AllowOverride All
    Require all granted
</Directory>

# Order matters. This alias must come first.
Alias /zm/cache "/var/cache/zoneminder"
<Directory "/var/cache/zoneminder">
    Options -Indexes +FollowSymLinks
    AllowOverride None
    <IfModule mod_authz_core.c>
       # Apache 2.4
       Require all granted
    </IfModule>
</Directory>

Alias /zm /usr/share/zoneminder/www
<Directory /usr/share/zoneminder/www>
  Options -Indexes +FollowSymLinks
  <IfModule mod_dir.c>
    DirectoryIndex index.php
  </IfModule>
</Directory>

# https://wiki.zoneminder.com/API#Example_Configuration_for_%2Fetc%2Fapache2%2Fconf-enabled%2Fzoneminder.conf
# For better visibility, the following directives have been migrated from the
# default .htaccess files included with the CakePHP project.
# Parameters not set here are inherited from the parent directive above.
<Directory "/usr/share/zoneminder/www/api">
   RewriteEngine on
   RewriteRule ^$ app/webroot/ [L]
   RewriteRule (.*) app/webroot/$1 [L]
   RewriteBase /zm/api
</Directory>

<Directory "/usr/share/zoneminder/www/api/app">
   RewriteEngine on
   RewriteRule ^$ webroot/ [L]
   RewriteRule (.*) webroot/$1 [L]
   RewriteBase /zm/api
</Directory>

<Directory "/usr/share/zoneminder/www/api/app/webroot">
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteBase /zm/api
</Directory>

Now we enable the configurations in Apache2:

$ sudo su -
root$ a2enmod cgi
root$ a2enmod rewrite
root$ a2enmod expires
root$ a2enmod headers
root$ a2enconf zoneminder
root$ systemctl restart apache2.server
root$ systemctl enable zoneminder.service
root$ systemctl restart zoneminder.service
root$ systemctl status zoneminder.service
root$ netstat -vnatp | grep apache2
root$ exit

Web Interface

Now the web interface is setup and running, and you should be able to access it at http://localhost/zm/.

Once you are able to access it via the web browser, you can configure it for your needs by following the ZoneMinder documentation.

Configuring Additional Drives

If you chose the setup that we chose, where you install Ubuntu 24.04 LTS on an SSD and have several spinning hard drives where you want to save all the video files to, you have to follow the below steps.

We assume the external drives are setup using LVM. If you have not done that, then you can follow an LVM tutorial here.

Once your drive(s) have been created, mounted and available, make sure they are mounted at /zoneminder or a similar folder. For this example, we mounted the logical volumes at /zoneminder.

$ sudo su -
root$ ls /zoneminder
root$ mkdir -p /zoneminder/events
root$ mkdir -p /zoneminder/images
root$ chown -R www-data:www-data /zoneminder

Edit the /etc/zm/conf.d/01-system-paths.conf or similarly named file where the variable ZM_DIR_EVENTS is defined and change it to point to the folder created above. By default, it will point to /var/cache/zoneminder/events and we change it to /zoneminder/events.

ZM_DIR_EVENTS=/zoneminder/events

Restart everything.

root$ systemctl restart zoneminder