(Solved)API not working with PHP 7.2 and Bionic 18.04

Forum for questions and support relating to the 1.31.x releases only.
User avatar
knight-of-ni
Posts: 2306
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: API not working with PHP 7.2

Post by knight-of-ni » Sat Mar 17, 2018 11:34 pm

Maybe you have tried this already, but here is what I did on a system running zoneminder 1.31.x with a working api:

Code: Select all

git clone https://github.com/cakephp
cd cakephp
git checkout 2.8.10
sudo mv /usr/share/zoneminder/www/api/lib /usr/share/zoneminder/www/api/lib-bak
sudo cp -r lib /usr/share/zoneminder/www/api
I simply updated the cake lib folder, and nothing more.

After I did that, https://localhost/zm/api/host/getVersion.json returned the version of zoneminder, and (after I set cake debug to level 2) the following url reported I was now running cakephp 2.10.8: https://localhost/zm/api/

I'm still running php 7.1 on Fedora 27, so I don't know if that will work for you or not. Feedback is requested.

As I'm sure you noticed, I completely ignored the "app" folder. I noticed Kyle's original api work is hopelessly entangled with all the original files under there... so I'll need to go through that file-by-file to see if there is anything that needs to be done. It's entirely possible I've overlooked something.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

User avatar
knight-of-ni
Posts: 2306
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: API not working with PHP 7.2

Post by knight-of-ni » Sun Mar 18, 2018 1:18 am

I did a closer comparison of the files under ZoneMinder's cake app folder and the files under the app folder in cake's git repo. I did not see anything significant we needed to care about. Most of the differences I saw were changes to the comments at the top of each file.

I did a side by side comparison of the contents of many of the files, and I looked for blocks of code that did not match up, or were shifted up or down inside the file. I did not find any cases like that, so if there is anything we need, it is going to be really small.

UPDATE:
Created a preliminary Pull Request:
https://github.com/ZoneMinder/zoneminder/pull/2067

It needs further testing before we know this really fixes the issue with php 7.2 or not.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

rockedge
Posts: 1154
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: API not working with PHP 7.2

Post by rockedge » Sun Mar 18, 2018 4:27 pm

I was able to get the API in version 1.30.4 and 1.31.39 to work with PHP 7.0 or 7.1 ....... but all the attempts using the same methods and also just replacing the /api/lib folder with the revised Cake.....but using PHP 7.2. I am only able to get cakephp error pages or a browser blank page and error.log reports. I have tried swapping out the /api/app/Plugin/Crud with newer versions and some directly from working ZM API's including a swap of the /api/app folder then tries with the /api/app folder completely fresh and adding each piece of code one by one and test the url http://localhost/zm/api/host/getVersion.json for each change.....I always end up back to the original error.

Code: Select all

/usr/share/zoneminder/www/api/app/webroot/index.php|PHP Fatal error:  Cannot use 'Object' as class name as it is reserved in /usr/share/zoneminder/www/api/lib/Cake/Core/Object.php on line 30
/usr/share/zoneminder/www/api/app/webroot/index.php|PHP Fatal error:  Class 'Object' not found in /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php on line 58
/usr/share/zoneminder/www/api/app/webroot/index.php|CGI returned 500 Internal Error
there is a problem getting the API to work running ZoneMinder on PHP 7.2.
I will again start fresh and try your suggestion knnniggett I think I have performed the update in similar fashion and several other attempts. Some bootstrap.php and/or index.php may need to be looked at closer in the /api/lib/Cake folder and other positions.

rockedge
Posts: 1154
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: API not working with PHP 7.2

Post by rockedge » Sun Mar 18, 2018 4:39 pm

this error has stopped progress on several attempts to get the API going with PHP 7.2

Code: Select all

127.0.0.1|Sun 18 Mar 2018 12:36:44 -0400|/usr/share/zoneminder/www/api/app/webroot/index.php|PHP Fatal error:  Uncaught LogicException: Passed array does not specify an existing static method (class 'App' not found) in /usr/share/zoneminder/www/api/lib/Cake/bootstrap.php:145|Stack trace:|#0 /usr/share/zoneminder/www/api/lib/Cake/bootstrap.php(145): spl_autoload_register(Array)|#1 /usr/share/zoneminder/www/api/app/webroot/index1.php(90): include('/usr/share/zone...')|#2 {main}|  thrown in /usr/share/zoneminder/www/api/lib/Cake/bootstrap.php on line 145

User avatar
knight-of-ni
Posts: 2306
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: API not working with PHP 7.2

Post by knight-of-ni » Sun Mar 18, 2018 5:08 pm

With regards to this error:

Code: Select all

/usr/share/zoneminder/www/api/app/webroot/index.php|PHP Fatal error:  Cannot use 'Object' as class name as it is reserved in /usr/share/zoneminder/www/api/lib/Cake/Core/Object.php on line 30
Take a look at the latest version of Object.php from the cakephp 2.x branch:
https://github.com/cakephp/cakephp/blob ... Object.php

The error message you posted, does not match the contents of this file. The newest copy of Object.php is only 18 lines long, and it maps CakeObject -> Object as a class_alias which I assume fixes the incompatibility with php 7.2.

However, the error you posted does match up with the non-php 7.2 compatible copy of Object.php currently found in our master branch:
https://github.com/ZoneMinder/zoneminde ... Object.php

Note also, we know the ZoneMinder API, as it is currently written, is not in any way compatible with cakePHP 3.x, so I recommend you not spend any time experimenting with those versions.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

rockedge
Posts: 1154
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: API not working with PHP 7.2

Post by rockedge » Sun Mar 18, 2018 9:18 pm

I do realize that version 3+ was going to fail. I am managed to get this page..but no css for some reason....
zm_api_page.png
zm_api_page.png (146.91 KiB) Viewed 8834 times

User avatar
knight-of-ni
Posts: 2306
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: API not working with PHP 7.2

Post by knight-of-ni » Mon Mar 19, 2018 12:04 pm

Huh, I'm struggling to read the text in that screenshot, and I'm remembering what the eye doctor told me last week when I went in to get another year of contacts. I'm in the age group where my vision will start to change. Oh joy.

The stuff in red... URL Rewriting... that's an Apache configuration error. That's an issue either with the .htaccess files mentioned earlier, or you've got a global command overriding them. Hope that helps.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

rockedge
Posts: 1154
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: API not working with PHP 7.2

Post by rockedge » Mon Mar 19, 2018 2:20 pm

thanks for the suggestion....you can ignore the URL re-write warning.....I am using Hiawatha instead of Apache...and the re-write looks like this:

Code: Select all

UrlToolkit {
  ToolkitID = api_rule
  Match ^/zm/api Rewrite  /zm/api/app/webroot/index.php$1
}
then applied in the virtual host block:

Code: Select all

VirtualHost {
Hostname = 192.168.0.*
WebsiteRoot = /var/www/hiawatha
StartFile = index.php
AccessLogfile = /var/log/access_log
ErrorLogfile = /var/log/error_log
TimeForCGI = 3600
ShowIndex = yes
ExecuteCGI = yes
FollowSymlinks = yes
#    UseFastCGI = PHP5
#    TriggerOnCGIstatus = yes    
NoExtensionAs = cgi
EnablePathInfo = yes    
#    Alias = /cgi-bin:/usr/local/libexec/zoneminder/cgi-bin
Alias = /cgi-bin:/usr/lib/zoneminder/cgi-bin
Alias = /zm:/usr/share/zoneminder/www
Alias = /phpmyadmin:/usr/share/phpmyadmin
UseLocalConfig = yes
UseToolkit = api_rule
}
but that leads to me think I need to try this all with a Bionic running Apache2 PHP 7.2 MariaDB..... I don't see that being the reason since every other version using Hiawatha and the URL re-writes it uses works really well.......but to eliminate the possibility and when I find the fix it should be for an Apache - ZM setup since the majority of the users of ZM run this configuration and who knows? maybe jar something into place or expose what is breaking the API

bbunge
Posts: 2698
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: API not working with PHP 7.2

Post by bbunge » Mon Mar 19, 2018 5:50 pm

Set up 18.04 with Mariadb-server and PHP7.2.
Downloaded the zoneminder_1.31.1~20180315113757-bionic_amd64.deb from the ppa-master. Noticed in prior attempts that the install would show errors installing Zoneminder; database not crested.
Unpackaged the file and made the following changes:
control file: removed zoneminder-doc
postinst: changed the grant string to just grant all in two places
Repackaged and installed from the .deb file on the hard drive with no errors! Database was created!

Now to finish the install and work on the api issues! Warm sunny afternoon and the road and bike is calling...

rockedge
Posts: 1154
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: API not working with PHP 7.2

Post by rockedge » Mon Mar 19, 2018 5:59 pm

slightly too cold and windy today here and some storm is on it's way....but now with Apache,PHP 7.2,MariaDB and zoneminder_1.31.39~20180306204157-bionic_i386.deb I ran into this again same as with Hiawatha....

Code: Select all

Fatal error: Uncaught Error: Class 'RelatedModelsListener' not found in /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php:752 Stack trace: 
#0 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(728): CrudComponent->_loadListener('RelatedModels') 
#1 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(169): CrudComponent->_loadListeners() 
#2 /usr/share/zoneminder/www/api/lib/Cake/Utility/ObjectCollection.php(128): CrudComponent->initialize(Object(CakeErrorController)) 
#3 /usr/share/zoneminder/www/api/lib/Cake/Event/CakeEventManager.php(243): ObjectCollection->trigger('initialize') 
#4 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(677): CakeEventManager->dispatch(Object(CakeEvent)) 
#5 /usr/share/zoneminder/www/api/lib/Cake/Error/ExceptionRenderer.php(158): Controller->startupProcess() 
#6 /usr/share/zoneminder/www/api/lib/Cake/Error/ExceptionRenderer.php(95): ExceptionRenderer->_getController(Object(FatalErro in /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php on line 752

User avatar
knight-of-ni
Posts: 2306
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: API not working with PHP 7.2

Post by knight-of-ni » Mon Mar 19, 2018 6:32 pm

You were right to upgrade the crud module as well.

It seems we need to upgrade to at least version 5.2.0 of Crud for php 7.2 compatibility:
https://github.com/FriendsOfCake/crud/r ... /tag/5.2.0
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

User avatar
knight-of-ni
Posts: 2306
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: API not working with PHP 7.2

Post by knight-of-ni » Mon Mar 19, 2018 8:02 pm

Oh, crud (no pun intended). Versions of Crud > 3.0.10 seem to require cakephp > 3.0 ...at least they do when using composer so this might get ugly.

https://github.com/FriendsOfCake/crud/b ... r.json#L43
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

rockedge
Posts: 1154
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: API not working with PHP 7.2

Post by rockedge » Tue Mar 20, 2018 3:16 pm

I have cakephp 2.10.8 with crud-c3976f1478c681b0bbc132ec3a3e82c3984eeed5 in the /zm/api. I am working with

Code: Select all

Apache/2.4.29 (Ubuntu), 
PHP 7.2, 
10.1.29-MariaDB-6 Ubuntu 18.04
zoneminder_1.31.1~20180315113757-bionic_i386.deb
I started off getting a fairly normal cakephp page with the css working and most things green then swapped in the /api/app from a working API from ZM 1.31.39 Artful(Ubuntu)17.10 and the errors prevented any function. So returned to the stock cakephp 2.10.8 and started to just concentrate on getting the URL http://localhost/zm/api/host/getVersion.json or http://localhost/zm/api/host/daemonCheck.json to work by just adding the code to get that going. I have had some cakephp generated error pages...not a bad sign....and now face this error

Code: Select all

Fatal error: Uncaught Error: Class 'RelatedModelsListener' not found in /usr/share/zoneminder/www/api/app2108/Plugin/Crud/Controller/Component/CrudComponent.php:752 Stack trace: #0 /usr/share/zoneminder/www/api/app2108/Plugin/Crud/Controller/Component/CrudComponent.php(728): CrudComponent->_loadListener('RelatedModels') #1 /usr/share/zoneminder/www/api/app2108/Plugin/Crud/Controller/Component/CrudComponent.php(169): CrudComponent->_loadListeners() #2 /usr/share/zoneminder/www/api/lib/Cake/Utility/ObjectCollection.php(128): CrudComponent->initialize(Object(CakeErrorController)) #3 /usr/share/zoneminder/www/api/lib/Cake/Event/CakeEventManager.php(243): ObjectCollection->trigger('initialize') #4 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(677): CakeEventManager->dispatch(Object(CakeEvent)) #5 /usr/share/zoneminder/www/api/lib/Cake/Error/ExceptionRenderer.php(158): Controller->startupProcess() #6 /usr/share/zoneminder/www/api/lib/Cake/Error/ExceptionRenderer.php(95): ExceptionRenderer->_getController(Obje in /usr/share/zoneminder/www/api/app2108/Plugin/Crud/Controller/Component/CrudComponent.php on line 752
the little signs of success or progress are few so far.....but not all is lost.....
weird is I added Crud 5.2 to see what happened......just this error ....

Code: Select all

Fatal error: Class 'Cake\Controller\Component' not found in /usr/share/zoneminder/www/api/app2108/Plugin/Crud/Controller/Component/CrudComponent.php on line 25

bbunge
Posts: 2698
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: API not working with PHP 7.2

Post by bbunge » Tue Mar 20, 2018 6:08 pm

18.04, Mariadb, PHP7.2 ZM 1.31.1
renamed /usr/share/zoneminder/www/api to api.save.
Created new copied cakephp-2.10.8 to /usr/share/zoneminder/www/ and renamed it to /usr/share/zoneminder/www/api
http://192.168.50.2/zm/api/host/getVersion.json told me I needed to create http://192.168.50.2/zm/api/app/Controll ... roller.php withe the contents:
<?php
class HostController extends AppController {
public function getVersion.json() {

}
}

Now http://192.168.50.2/zm/api/host/getVersion.json shows this:
cake1.jpg
cake1.jpg (144.45 KiB) Viewed 8771 times

rockedge
Posts: 1154
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: API not working with PHP 7.2

Post by rockedge » Tue Mar 20, 2018 8:47 pm

In the zoneminder /api folder is /api/app. And inside /api/app/Controller there are the controllers code files that do the connections and functions with zoneminder like /api/app/Controller/HostController.php
Also in /api/app/Models are files that need to be present for the interaction with ZM.
Important are the /api/app/Config files dataase.php, core.php, bootstrap.php these load functions and set where to find the ZM config files needed to make the database connections.
There are other custom bootstrap.php files also needed.....
Right now I am adding just enough for /api/app/COntroller/HostController.php to function program by program.

Look in the /api/app folder on a working API to see what files are needed. I must be missing some small detail.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests