Page 1 of 1
Problems enabling PHP
Posted: Wednesday 10 January 2018 16:18
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
Re: Problems enabling PHP
Posted: Wednesday 10 January 2018 16:23
by Egregius
I would suggest running Apache2, lighttpd, Nginx... besides domoticz.
Re: Problems enabling PHP
Posted: Wednesday 10 January 2018 17:02
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?
Re: Problems enabling PHP
Posted: Wednesday 10 January 2018 17:23
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.
Re: Problems enabling PHP
Posted: Wednesday 10 January 2018 17:25
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
Re: Problems enabling PHP
Posted: Wednesday 10 January 2018 17:29
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

Re: Problems enabling PHP
Posted: Friday 02 February 2018 10:32
by DewGew
Help needed. I installed php5-cgi.
When i try to open my php file I get error '404 Not found'.
Re: Problems enabling PHP
Posted: Sunday 26 April 2020 18:06
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:
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?
Re: Problems enabling PHP
Posted: Thursday 13 January 2022 19:26
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.
Re: Problems enabling PHP
Posted: Friday 14 January 2022 20:59
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.
Re: Problems enabling PHP
Posted: Friday 14 January 2022 21:35
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

Re: Problems enabling PHP
Posted: Sunday 16 January 2022 8:46
by Lokonli
Ok, sounds good. Let's do that.
Verstuurd vanaf mijn AC2003 met Tapatalk
Problems enabling PHP
Posted: Sunday 16 January 2022 9:28
by kiddigital
Lokonli wrote:Ok, sounds good. Let's do that.
Better to create a new topic? General - Suggestions category?
Re: Problems enabling PHP
Posted: Sunday 16 January 2022 9:42
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?
Re: Problems enabling PHP
Posted: Sunday 16 January 2022 11:03
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