I have written a small part of php code, that have access to DBus by commandline. But when I run the php code from the browser, dbus part doesn't work.
Do I have to do something in order to have access to the DBus from browser?
I have written a small part of php code, that have access to DBus by commandline. But when I run the php code from the browser, dbus part doesn't work.
Do I have to do something in order to have access to the DBus from browser?
When invoked through a web server, PHP does not necessarily use the same user and therefore have the same privileges compared to when it's invoked over the command line.
try running the following script in the browser and then through the command line:
<?php echo exec('whoami'); ?>
This might output e.g. apache for when you run it through the browser and myusername when you run it through the CLI.
So you would need to change the privileges for the user that your webserver is running as to allow it to run the DBus commands. How you do that will depend on your OS.
Also see this question for more hints: Running command-line application from PHP as specific user
PHP executed on a web server (like Apache) can't do D-Bus requests at all. I'm trying for several days without success. This is because the web server user (like www-data
) can't access the dbus-daemon
via a session
connexion.
As a workaround I'm using the React built-in HTTP server as a proxy.