Page 1 of 2

API not working with 1.34.21 and CakePHP 2.10.11

Posted: Fri Nov 13, 2020 10:15 pm
by steelskin
Hi,

So basics first. Zoneminder 1.34.21 (Connors PPA), CakePHP 2.10.11 and PHP 7.4. Running on a raspberry pi 4 model B 8GB on Ubuntu 20.10. The normal zoneminder web interface is working fine and I'm not getting any errors in the zoneminder log. I have ZM authentication setup and that's working fine.

I've been struggling with this issue for days, basically and initially, I get the infamous CakePHP error "The requested address '/zm/api/; was not found on this server when I try to access localhost/zm/api.

Oddly enough, I can get the expected correct page if I enable level 2 debugging by editing /usr/share/zoneminder/www/api/app/Config/core.php "Configure::write('debug', 2); which was previously a '0' instead of a '2'.

I then get the expected release notes for CakePHP 2.10.11 followed by the highlighted green bands that say "Your version of PHP is 5.2.8 or higher", "Your tmp directory is writable" (it wasn't at first but that was fixed after I chown'ed www-data:www-data /var/cache/zoneminder/temp which had root:root ownership. "The ApcEngine is being used for core caching", Your database configuration file is present", CakePHP is able to connect to the database" and finally "DebugKit is not installed", which presumably isn't mandatory. So all the above is highlighted in green and so appears ok. Now if you scroll right down to the bottom of the page you should see SQL query information, at least I do on other older installations but not here. There is no SQL query information. Is that a clue?

Also if I try to access http://localhost/zm/api/host/getVersion.json I just get the default apache2 message "Not Found, The requested URL was not found on this server.

Multiple de-installs and re-installs haven't fixed the problem and I'm starting to wonder if it's some issue with the fact I'm using CakePHP 2.10.11 instead of 2.10.8?

The zoneminder installation procedure I used was as follows, taken from the zoneminder installation guide for Ubuntu 18.04 here https://zoneminder.readthedocs.io/en/la ... -04-bionic
add-apt-repository ppa:iconnor/zoneminder-1.34
apt-get update
apt-get upgrade
apt-get dist-upgrade
rm /etc/mysql/my.cnf (this removes the current symbolic link)
cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf
nano /etc/mysql/my.cnf
In the [mysqld] section add the following
sql_mode = NO_ENGINE_SUBSTITUTION
systemctl restart mysql
apt-get install zoneminder
mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
mysql -uroot -p -e "grant lock tables,alter,drop,select,insert,update,delete,create,index,alter routine,create routine, trigger,execute on zm.* to 'zmuser'@localhost identified by 'zmpass';" (The second mysql failed with a authentication issue but by repeating by removing the "identified by 'zmpass'" it then worked.
chmod 740 /etc/zm/zm.conf
chown root:www-data /etc/zm/zm.conf
chown -R www-data:www-data /usr/share/zoneminder/
a2enmod cgi
a2enmod rewrite
a2enconf zoneminder
a2enmod expires
a2enmod headers
systemctl enable zoneminder
systemctl start zoneminder
nano /etc/php/7.4/apache2/php.ini
with date.timezone = Europe/London
systemctl reload apache2

Any clues as to how I can diagnose this problem? It seems to be that CakePHP isn't translating the request for http:/localhost/zm/api/host/getVersion.json to the appropriate route?

As mentioned early, is the fact that the sql query isn't shown at the bottom of the page when you access http://localhost/zm/api/.

From the command line I can log into mysql with the command 'mysql -uzmuser -pzmpass' then 'use zm;' and 'show tables' so I know the mysql login is working ok.

Any help is much appreciated, especially from CakePHP experts.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Sat Nov 14, 2020 3:14 am
by burger
Use 20.04.
https://wiki.zoneminder.com/Ubuntu
https://wiki.zoneminder.com/Debian

Only install on distributions from these guides if you want it to work without advanced knowledge.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Sat Nov 14, 2020 3:42 am
by iconnor
ZoneMinder ships with it's own cakephp. Do not substitute your own.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Sat Nov 14, 2020 9:10 pm
by steelskin
Hi, I didn't substitute my own, 2.10.11 is the version that's in the 20.10 repository. Zoneminder seems to be using the repository version rather than the zoneminder built in version. I've not copied any files into /usr/share/zoneminder/www/api just followed the installation instructions for zoneminder.

If I try to remove CakePHP 2.10.11 via synaptic it also wants to remove zoneminder. Having checked the values of CAKE_CORE_INCLUDE_PATH which is /usr/share/zoneminder/www/api/lib and ROOT which is /usr/share/zoneminder/www/api they both are as they should be so. I did notice that if you logout so that you are no longer authenticated, you get the not authenticated message generated by CakePHP and it shows a stack trace that points to /usr/share/php/Cake which is where presumably the 2.10.11 version dispatcher/controller files are, rather than /usr/share/zoneminder/www/api/lib or app.

Anybody else successfully using the api on Ubuntu 20.10 64bit? Currently I'm running Zoneminder and ZmNinja on two other older 1.32 zoneminder installations without any issues with the api.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Sat Nov 14, 2020 10:05 pm
by Markphoto
I have the same issue. Spent 2 days now and cannot get it to work.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Sun Nov 15, 2020 2:23 pm
by steelskin
Think I may be on to something now. The reason Zoneminder isn't using it's buildin cakephp 2.10.8 is that there is a symbolic link in /usr/share/zoneminder/www/api/lib called 'Cake' that points to ../../../../php/Cake, i.e the 2.10.11 version of cakephp located in /usr/share/php/Cake/.

Looking at Github, that's not the way it's supposed to be. Why there is a symbolic link there back to 2.10.11 rather than zoneminder's built in 2.10.8 version, I've no idea. I certainly didn't delete the contents /usr/share/zoneminder/www/api/lib and put a symbolic link in there. :shock:

I'll re-instate the correct lib contents and let you know if it works.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Sun Nov 15, 2020 2:49 pm
by steelskin
Looking further into the packaging side of this, I took a look at the files that get installed and the package actually contains the symbolic link. Further to this, it looks like I may have the ubuntu version of zoneminder installed which has had the build in CakePHP library removed and replaced with a symbolic link. Also although I think I'm installing the iconnor's launchpad PPA version, I'm not for some reason, it's defaulting to the Ubuntu version. I think that's the root cause of the problem. The Ubuntu version has had the in built cakephp stripped out.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Mon Nov 16, 2020 6:55 pm
by Markphoto
If you get a solution, please post it here

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Mon Nov 16, 2020 11:00 pm
by steelskin
Will do. I'm still working on it.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Wed Nov 18, 2020 1:22 am
by Bluemax
Maybe it has something to do with the official repo git tags being invalid now. They are still pointing to the old crud repo that (looks like) has been deleted ('git clone' asks for password, may break automated builds). If so, either clone from staging branch (release-1.34) or wait until next release (git tag).

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Thu Nov 19, 2020 10:22 am
by rkosiarz
Hi

Do you have any news here? I have the same issue.

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Fri Nov 20, 2020 9:59 am
by GoDie
Same issue here

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Thu Dec 03, 2020 7:59 pm
by Beetleboy
I have been using Zoneminder successfully for some time now on a Raspberry pi, version 1.34.22 of Zoneminder. And the API's can be a bit of an issue.
With the Pi, have used both the Debian packages and when I want a version that doesn't have an armhf package I build my own package and install it.

The issue I see is that the Debian package does not install the /usr/share/zoneminder/www/api/lib/Cake directory properly. It just installs a link to Cake as ../../../../php/Cake, which on the Pi really contains nothing.

When I build my own version of the package, the /usr/share/zoneminder/www/api/lib/Cake directory is populated as
drwxr-xr-x 19 root root 4096 Oct 21 11:09 .
drwxr-xr-x 3 root root 4096 Feb 8 2020 ..
-rw-r--r-- 1 root root 32815 Oct 19 13:59 basics.php
-rw-r--r-- 1 root root 14499 Oct 19 13:59 bootstrap.php
drwxr-xr-x 3 root root 4096 Oct 21 11:09 Cache
drwxr-xr-x 3 root root 4096 Oct 21 11:09 Config
drwxr-xr-x 2 root root 4096 Oct 21 11:09 Configure
drwxr-xr-x 5 root root 4096 Oct 21 11:09 Console
drwxr-xr-x 3 root root 4096 Oct 21 11:09 Controller
drwxr-xr-x 2 root root 4096 Oct 21 11:09 Core
drwxr-xr-x 2 root root 4096 Oct 21 11:09 Error
drwxr-xr-x 2 root root 4096 Oct 21 11:09 Event
drwxr-xr-x 2 root root 4096 Oct 21 11:09 I18n
drwxr-xr-x 3 root root 4096 Oct 21 11:09 Log
drwxr-xr-x 5 root root 4096 Oct 21 11:09 Model
drwxr-xr-x 4 root root 4096 Oct 21 11:09 Network
drwxr-xr-x 4 root root 4096 Oct 21 11:09 Routing
drwxr-xr-x 6 root root 4096 Feb 8 2020 Test
drwxr-xr-x 7 root root 4096 Oct 21 11:09 TestSuite
drwxr-xr-x 2 root root 4096 Oct 21 11:09 Utility
-rw-r--r-- 1 root root 1026 Oct 19 13:59 VERSION.txt
drwxr-xr-x 6 root root 4096 Oct 21 11:09 View

This directory structure contains all the appropriate Cake modules and the api runs fine, and ZMNinja works well with it.

So the Raspberry although its roots are Debian, it is not Debian. I am not a Debian package builder but I suspect somewhere in the package there is a minor issue with respect to setting up the Cake directory structure on the PI. It likely is looking for something Debian specific that doesn't exist on a Pi, but as I don't have a vanilla Debian Linux installation, I can't verify it.

So near term, there are a few options, one is to build your own package (not too difficult on a Pi) which does create the correct directory structure (the build instructions I think are really for Ubuntu, but they work fine see https://zoneminder.readthedocs.io/en/1. ... rom-source), or to install zoneminder on an Ubuntu system and copy over the directory structure from the above Cake directory to the same directory on the Pi. A third alternative would be to install Ubuntu server on the Pi and then install zoneminder on it, rather than using Raspian. As from what I can see, Cake is basically hardware agnostic so I have used both intel and armhf versions of the system as source.

Maybe someone who knows packaging better that I could look at the Debian packages and see if there is a way to make the Debian packages work on Raspian. That would be nice.

Hopefully this is clear, if not let me know and I will try to help out with issues you may be having

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Fri Feb 05, 2021 12:16 am
by CV8R
Hi All,

After upgrade to 1.34.23 I have the same issue. Is there a solution on how to correct the contents of /usr/share/zoneminder/www/api/lib/Cake directory?

Thanks
CV8R

Re: API not working with 1.34.21 and CakePHP 2.10.11

Posted: Mon Feb 08, 2021 10:48 am
by CV8R
I ended up installing ZoneMinder into an Ubuntu VM and copying the Cake path contents over to my regular server (also Ubuntu) and now the API works.