Fixing ZoneMinder and zmNinja on Upgrade to Ubuntu 22.04 LTS

Another quick technical post today to talk about getting ZoneMinder and zmNinja to work again after upgrading Ubuntu from 20.04 LTS to 22.04 LTS. If you’re struggling to get ZoneMinder working again, or having trouble connecting with zmNinja, after upgrading Ubuntu, then this is for you.

Background

I’m assuming, if you’re reading this, that you already know that ZoneMinder is a popular open-source software for handling closed-circuit television systems. Originally it was meant to work with analog cameras (mostly composite signal) and video digitiser boards, but nowadays of course it’s mostly IP cameras. In my case, like many others, I’m using this to monitor the feeds from the IP cameras scattered around our house, including that in the front doorbell.

I already had a working setup on Ubuntu 20.04 LTS. However, because the version available on the standard repos was too old (I can’t remember offhand what feature I needed that prompted the change), I was using version 1.34 from Isaac Connor’s PPA.

The Upgrade Process

When upgrading Ubuntu on the server box that handles ZoneMinder (among several other duties), I removed the PPA, to allow me to install the version on the standard repos (now 1.36). As these things go, the upgrade went reasonably well, and by the end of it I had the newer ZoneMinder installed, now from the Ubuntu repo rather than the PPA.

Getting ZoneMinder to Start Again

After the upgrade, ZoneMinder wasn’t running. I checked the logs (systemctl status zoneminder), to find that the issue was simply that the database was too old. Of course it was, I had just upgraded. Sensibly, ZM won’t just mess around with your data without your explicit say-so, which means that we need to trigger this update manually. This can be done from a terminal on the machine in question with:

sudo zmupdate.pl --user=root

Following this you’ll be prompted for the root password (the database/MySQL one, not the system user). Then you’ll need to leave the system do it’s thing for a potentially long time, if your database has a lot of events, as mine does. Just be patient.

Once the database upgrade is over, you’ll just need to restart the service (systemctl restart zoneminder), and check that everything is running ok again (check the log). Next, open a web browser at the corresponding address, to confirm that ZM is accessible through the web.

In my case this did not work. Going from the PPA to the Ubuntu repos caused some Apache settings to get messed up. In summary I needed to:

  • Change from PHP 7.4 to 8.1:
    • a2dismod php7.4
    • a2endmod php8.1
  • Enable the ZM configuration:
    • a2enconf zoneminder
  • Reload the Apache configuration
    • systemctl reload apache2

Getting the APIs to Work

At this point, I had ZoneMinder running, and skipping an issue I had with the DNS resolver (I’ll talk about that in a separate blog post), everything was fine. The only issue was that zmNinja, a convenient app that I use to view the feeds and otherwise interact with the system, was no longer connecting. There was nothing wrong with the app, which was working before the upgrade, so I figured something had changed in the ZM configuration.

The easiest way to diagnose whether the APIs are working is to open a web browser with the following address:

https://server.name/zm/api/host/getVersion.json

where server.name is the FQDN of the machine hosting ZM, so that the main web interface is at https://server.name/zm/.

If you get a 404 error, then the APIs aren’t working. It seem that this is due to a problem with the way ZM is packaged in the Ubuntu repos. It took me a while to find the correct fix to this, thanks to this ZM forum thread. In summary, you’ll need to edit the ZM configuration in Apache (sudo vi /etc/apache2/conf-available/zoneminder.conf). At the end of the file there is a Directory segment for the API which only has an AllowOverride setting. This needs to be updated with rewrite rules, and we also need to add rewrite rules in some subfolders. At the end, the file contents need to be as follows:

# Remember to enable cgi mod (i.e. "a2enmod cgi").
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>

<Directory /usr/share/zoneminder/www/api>
    AllowOverride All
    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>

After editing the file, reload the Apache configuration, and everything should be up and running again, with zmNinja connecting normally.

2 thoughts on “Fixing ZoneMinder and zmNinja on Upgrade to Ubuntu 22.04 LTS

  1. Thank you! After an ubuntu update my Zoneminder was totally trashed, such a pain. I had hunted down and reinstalled missing packages, migrated my database, re-installed Apache SSL module for HTTPS, and a few other things finally got ZM working but no zmNinja. Your post FINALLY had the key missing information!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.