Page 1 of 4
Zoneminder 1.30.4 API not working on FreeBSD
Posted: Tue Apr 17, 2018 8:46 pm
by n8klayko
I have installed zoneminder directly into a FreeNAS jail using the following guide and a few tweaks to get almost everything working correctly. Unfortunately one thing is
not working, the APIs. To reduce overhead I really want to run zoneminder through the jail on my server rather than in a VM. I have already set it up once on a VM and was not very please with the performance/scalability versus the jail installation.
https://forums.freenas.org/index.php?th ... jail.62135
When testing the APIs, by going to "
http://server/api/host/getVersion.json", I receive a 404 Not found error.
https://github.com/pliablepixels/zmNinj ... work-on-ZM
Something to note is that the directory structure of the FreeBSD jail version is different than an Ubuntu VM install. The address of my zoneminder installation does not require the "zm" at the end of the URL. Additionally, the API folder is in a different location "/jails/zm/usr/local/www/zoneminder/api". I have searched everywhere to see if I can find a solution to get the APIs working and have not found a clear cut answer. I am hoping that someone may be able to help me figure out if I am missing a dependency or something that is not allowing the APIs to work. Any help is greatly appreciated.
The closest thing to a solution that I have found is the below thread, but I am not sure what to do to resolve the issue.
viewtopic.php?t=26131
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 3:21 pm
by rockedge
the not found error seems to indicate a URL re-write is not occurring as expected. I run ZM with a Hiawatha web server and needed to make a UrlToolkit that does the URL re-writes similar to what happens in Apache. Possibly check the paths that the re-write rule creates for the api access. You can add the pieces needed to rewrite
/jails/zm/usr/local/www/zoneminder/api to a workable url.
the Hiawatha rule looks like this:
Code: Select all
UrlToolkit {
ToolkitID = api_rule
Match ^/zm/api Rewrite /zm/api/app/webroot/index.php$1
}
maybe look in the /usr/share/zoneminder/www/api/.htaccess file:
Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteBase /zm/api
</IfModule>
and change the RewriteBase /zm/api to match your url /jails/zm/usr/local/www/zoneminder/api
see if that does it.
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 3:41 pm
by rockedge
what version of PHP are you using?
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 3:59 pm
by n8klayko
rockedge wrote: ↑Wed Apr 18, 2018 3:21 pm
maybe look in the /usr/share/zoneminder/www/api/.htaccess file:
Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteBase /zm/api
</IfModule>
and change the RewriteBase /zm/api to match your url /jails/zm/usr/local/www/zoneminder/api
see if that does it.
I attempted to change the
.htaccess file in the api directory. I rebooted apache and zoneminder then re-tested, but to no avail.
I appear to be missing files and folders in the api directory. To my knowledge, I should have a
hosts folder located in the api directory with files in it, but there is no hosts folder.
I should also mention that everything else appears to be working with the web interface, viewing monitors, viewing events, etc.
Respectfully,
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 4:01 pm
by n8klayko
rockedge wrote: ↑Wed Apr 18, 2018 3:41 pm
what version of PHP are you using?
After checking the PHP version using
, it shows that PHP 5.6.34 is installed in my ZM jail.
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 4:16 pm
by rockedge
no there will be no actual "host" folder. This is a controller name in the API, this controller code has the functions like "getVersion" in it.
There is a case of missing folders that are talked about on this forum but they are cache folders that did not get installed. That could also be a problem and was fixed just by adding the missing folders but I think it is a re-write problem and the API is being found.
what happens when you use this url?
http://your-zm-server/zm/api in your case
http://your-zm-server/api ?
what is the error?
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 4:19 pm
by rockedge
go to /usr/share/zoneminder/www/api/app/Config/core.php and look at line 34
and change the 0 to a 2. this will enable more error reporting and allow the url /zm/api (or equivalent to work)
then try the url
http://your-zm-server/zm/api or in your case
http://your-zm-server/api
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 4:28 pm
by rockedge
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 4:38 pm
by n8klayko
@rockedge, you are correct, it looks like a rewrite issue. Any thoughts?

- error.PNG (21.63 KiB) Viewed 6543 times
Also, I really appreciate you taking the time to help me out on this! Thanks!
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 6:35 pm
by n8klayko
I managed to fix the rewrite issue. In my system
httpd.conf file, the line
Code: Select all
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
was commented out. I removed the proceeding "
#" as explained here:
https://book.cakephp.org/2.0/en/install ... iting.html
Additionally, I had to change my
.htaccess files in the directories
api and
api/app to look like this:
Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
RewriteBase /api
</IfModule>
I am still having a permission issue with CakePHP as you can see from the below screenshot. I am not sure what permissions I need to change. Any thoughts?

- error2.PNG (86.41 KiB) Viewed 6538 times
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 7:56 pm
by rockedge
it is starting to look good. the error you are seeing I think, is from cakephp trying to write a log file in a folder someplace that does not have the permissions for www-data to write to it and so it does not exist. check that the directory the log file is writing to has the correct permissions and exists.
what does the URL /zm/api/host/getVersion.json do now?
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Wed Apr 18, 2018 8:10 pm
by rockedge
look in /usr/share/zoneminder/www/api/app/Config/bootstrap.php around line 100
maybe one of these paths to the log directory in question,
Code: Select all
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'File',
'types' => array('notice', 'info', 'debug'),
'file' => 'cake_debug',
'path' => '/var/log/zm/'
));
CakeLog::config('error', array(
'engine' => 'File',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'cake_error',
'path' => '/var/log/zm/'
));
CakeLog::config('custom_path', array(
'engine' => 'File',
'path' => '/var/log/zm/'
));
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Thu Apr 19, 2018 4:26 pm
by n8klayko
When testing the APIs, by going to
http://server/api/host/getVersion.json, I am still receiving a 404 Not found error. Again, because this is directly in a FreeNAS Jail, the
/zm/ is not needed for the correct path. The path to my server is
http://server/ without the added
/zm/ directory
Looking at the
api/app/Config/bootstrap.php, the paths you mentioned look to be mostly correct. But the file is a little different than what you have:
Code: Select all
CakeLog::config('debug', array(
'engine' => 'File',
'types' => array('notice', 'info', 'debug'),
'file' => 'cake_debug',
));
CakeLog::config('error', array(
'engine' => 'File',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'cake_error',
));
CakeLog::config('custom_path', array(
'engine' => 'File',
'path' => '/var/log/zm'
));
I tried switching this to reflect yours but it seems to break everything. Switching it back corrected it, but I am still left with the
mkdir permissions error from CakePHP. Looking at my Zoneminder installation it looks like the path above "
/var/log/zm" is mostly correct, but I do not have a
/zm/ directory inside of my "/var/log" directory.
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Mon Apr 23, 2018 2:22 pm
by n8klayko
BUMP
Re: Zoneminder 1.30.4 API not working on FreeBSD
Posted: Mon Apr 23, 2018 2:24 pm
by n8klayko
I am very close on this. The mkdir CakePHP issue is the only thing that looks to be preventing the API from working. I am not sure if this is a permission error or an error in a config file. Any guidance would be greatly appreciated.