Problems enabling PHP

Moderator: leecollings

Post Reply
josvink66
Posts: 4
Joined: Monday 08 January 2018 15:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Problems enabling PHP

Post by josvink66 »

Hello,

I'm trying to enable PHP with the Domoticz webserver. But it's not working.
I've read that you need to supply the argument to the php cgi.

I've installed php7.0 and php7.0-cgi. I've changed the /etc/init.d/domitcz.sh to include the path to php:
DEAMON_ARGS="$DEAMON_ARGS -php_cgi_path /usr/bin/php7.0-cgi"
But when i put a php file in the www folder i get: 501 Not Implemented
I've also try't it with php5, same effect.

Any idea's?

Greetings,
Jos Vink
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Problems enabling PHP

Post by Egregius »

I would suggest running Apache2, lighttpd, Nginx... besides domoticz.
josvink66
Posts: 4
Joined: Monday 08 January 2018 15:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problems enabling PHP

Post by josvink66 »

Egregius wrote: Wednesday 10 January 2018 16:23 I would suggest running Apache2, lighttpd, Nginx... besides domoticz.

Yes i was looking for that, but the page https://www.domoticz.com/wiki/Secure_Nginx_Proxy_Setup has no info anymore..
I've set up the webserver and php and set the documentfolder to /home/pi/domoticz/www but that did not work.

Do you know if there is any (working) tutorial out there?
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Problems enabling PHP

Post by Egregius »

It should be as simple as apt-get install apache2 I think.
Why would you use the same www folder? You can perfectly use a different folder.
Only downside of this way is that you'll have 2 port numbers.
In my case that's no problem because I only use the Apache web interface, the domoticz gui only for adding new devices.
josvink66
Posts: 4
Joined: Monday 08 January 2018 15:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problems enabling PHP

Post by josvink66 »

My first idea was to run all of domoticz and the php scripts from the webserver.
But i'm gonne run it side by side now.

Thanks
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Problems enabling PHP

Post by Egregius »

If you only use php for scripts that shouldn't be an issue.
If you also like to have pages available in a browser you need to consider which ports you gonna use.
I only use my php floorplan as a front gui, so I didn't need to make that decision ;)
User avatar
DewGew
Posts: 579
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Problems enabling PHP

Post by DewGew »

Help needed. I installed php5-cgi.
When i try to open my php file I get error '404 Not found'.
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
Lokonli
Posts: 2271
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problems enabling PHP

Post by Lokonli »

I'm trying to start php scripts via the Domoticz www server. I'm using Domoticz 2020.1, Debian 10

I've installed php-cgi.

I've added the PHP parameter for Domoticz:

Code: Select all

DEAMON_ARGS="$DEAMON_ARGS -php_cgi_path /usr/bin/php-cgi"
I've placed a php test file in the Domoticz www folder:

Code: Select all

<?php
print("Hallo/n");
?>
Via the command line I can execute the file:

Code: Select all

lokonli@test:~/domoticz/www$ php-cgi ~/domoticz/www/test.php
Content-type: text/html; charset=UTF-8

Hallo
However, browsing to http://<ip:8080/test.php gives a browser error 404 Not Found.

Interestingly, when I start domoticz from the command I line the following message appears in the console:

Code: Select all

sh: 1: Syntax error: "(" unexpected
That doesn't look ok.

So my question:
Is anyone succesfully using PHP scripts via the Domoticz server?
User avatar
waltervl
Posts: 5396
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Problems enabling PHP

Post by waltervl »

I succeeded. I also updated the wiki with some instructions: https://www.domoticz.com/wiki/Customization#PHP
The example is from the latest changes in Domoticz source code from @Lokonli

@Lokonli, what are the current restrictions for using the Domoticz webserver with php scripts? I see that Dashticz is served by an external webserver. You had your reasons I suppose.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Lokonli
Posts: 2271
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problems enabling PHP

Post by Lokonli »

waltervl wrote: Thursday 13 January 2022 19:26 I succeeded. I also updated the wiki with some instructions: https://www.domoticz.com/wiki/Customization#PHP
The example is from the latest changes in Domoticz source code from @Lokonli

@Lokonli, what are the current restrictions for using the Domoticz webserver with php scripts? I see that Dashticz is served by an external webserver. You had your reasons I suppose.
I will reply from Dashticz perspective.

When we added server functionality to Dashticz at that time PHP was not working in Domoticz.

Later, I tried to fix PHP support in Domoticz. I partly succeeded. However, there are still a few issues:

* If login is activated in Domoticz, then the www path is only accessible after successful login. That means the Dashticz dashboard won't load when the login cookie expires.
* If I remember correctly passing of query parameters from Domoticz to PHP is not fully implemented.
* Return codes from PHP via Domoticz to the client doesn't work.
* I tried to build for Windows as well. Unfortunately I was not able to get that working. That means, I don't know whether PHP is working with Domoticz on Windows.

Some additional things to investigate:
* Dashticz may initiate quite some network requests via Domoticz. Impact on performance should be validated.

So, I started to explore other directions: node.js backend with react frontend
I've a first prototype working. However, it will be quite some work to port all Dashticz functionality. Currently, I've put this on hold.

Or, as alternative: Dashticz requires only very minimal backend functionality. In fact only proxy functionality is needed to bypass CORS issues. So, if we could initiate a network request via the Domoticz json interface, including setting of cookies, then we are almost done. Then for Dashticz we only need a login mechanism. That may require some changes in Domoticz, but that should be doable. This way we completely get rid of the PHP dependency for Dashticz which probably makes more sense than trying to add full PHP support to the Domoticz server.
User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problems enabling PHP

Post by kiddigital »

I definitely want to assist here.

With the PR on OAuth2 (still pending as it needs time and testing) some/most of the issues on allowing good/secure communication between Domoticz and add-ons/clients like Dashticz are solved.

Also I agree that expanding the Domoticz webserver to get more/better PHP support isn’t a direction I would favor.

Maybe it is a good idea to work-out a sort of proposal how a more optimal solution could look like and I would be happy to help in developing it.

Something to sleep about
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
Lokonli
Posts: 2271
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problems enabling PHP

Post by Lokonli »

Ok, sounds good. Let's do that.

Verstuurd vanaf mijn AC2003 met Tapatalk

User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Problems enabling PHP

Post by kiddigital »

Lokonli wrote:Ok, sounds good. Let's do that.
Better to create a new topic? General - Suggestions category?
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problems enabling PHP

Post by kiddigital »

@Lokonli , the need for a CORS ‘proxy’ is that because for certain Dashticz special blocks certain http requests have to be done to ‘external’ sites for information that is than processed and use in these blocks?

Would it be an idea if that processing would be done at the Domoticz end (maybe a Python plugin) so Dashticz can request it from Domoticz itself?
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
Lokonli
Posts: 2271
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problems enabling PHP

Post by Lokonli »

kiddigital wrote: Sunday 16 January 2022 9:42 @Lokonli , the need for a CORS ‘proxy’ is that because for certain Dashticz special blocks certain http requests have to be done to ‘external’ sites for information that is than processed and use in these blocks?

Would it be an idea if that processing would be done at the Domoticz end (maybe a Python plugin) so Dashticz can request it from Domoticz itself?
yes, exactly
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest