I was having difficulty getting the ZoneMinder module to work with HomeAssistant, running on Ubuntu 16.04. I was getting an error about invalid credentials (sorry, didn’t record the error). It turned out that the problem was with the APC cache not working properly in the ZoneMinder API. While I didn’t carefully record all of my steps, here are some general pointers for you to help you in running it down.
First, the best way to test whether the ZoneMinder API is working is just to fetch the URL http://{my.server.com}/zm/api/host/getVersion.json . Note that you should first get your authentication cookie in your browser (by logging into ZoneMinder normally through the browser). Until you get a good version message back from ZoneMinder, your overall API isn’t working.
You can find information in general about the ZoneMinder API here.
To troubleshoot what’s going on in the API, pay attention to your Apache logs. And when you change something in general (e.g., with PHP, which we’re going to get to) be sure to restart all the appropriate services! (Apache and ZoneMinder at least).
In my case, the problem appears to be that my system went from PHP 5.5 to PHP 7.0 as the base PHP after I’d installed ZoneMinder. As far as I understand it, PHP 5.5 supported APC as its cache, but that support was removed (by default) in PHP 7.0. The Cake module, which is used as the basis of the ZoneMinder API, is set to use APC by default as its cache.
To fix this, you could either edit the default cache for Cake (look in your ZoneMinder PHP files under the API directory, and in one of the initialization files you’ll find the default being set to APC — I think if you set it to “file” instead you’ll disable caching). Or, as I did, you can enable backwards-compatible APC caching in Apache/PHP 7.0. In general, this means enabling APCu caching in Apache (which is the current implementation), then enabling backwards compatibility to support APC. I don’t remember exactly which sites I used to work through this, but a Google search for “enable apcu php 7” should get you on the right track. I believe you have to get a module or two, and then make sure you’ve got both apc and apcu enabled for Apache.
One last thing I did — and I’m not sure if it was relevant or not — was to precreate some temporary directories according to this ZoneMinder forum post. That may have been a red herring … but it was part of my overall solution.
At this end of this, ZoneMinder works great with HomeAssistant, and the ZoneMinder API is back up and running!