Hello I am trying to execute a Python script with pyautogui library from PHP on apache2 server running on a Raspberry Pi. While executing the Python script from the command line I encounter no problems, but when doing so through PHP's "shell_exec" I get following error message:
error.log in apache2:
Traceback (most recent call last): File "/home/pi/Projects/Python/wakeUp.py", line 2, in import pyautogui File "/usr/local/lib/python3.4/dist-packages/pyautogui/init.py", line 115, in from . import _pyautogui_x11 as platformModule File "/usr/local/lib/python3.4/dist-packages/pyautogui/_pyautogui_x11.py", line 160, in _display = Display(os.environ['DISPLAY']) File "/usr/lib/python3.4/os.py", line 633, in getitem raise KeyError(key) from None KeyError: 'DISPLAY'
Python script (test.py):
#!/usr/bin/python3
import pyautogui
pyautogui.moveTo(25, 25, duration=1)
pyautogui.click()
PHP script (index.php):
<?php
shell_exec("python3 /home/pi/Projects/Python/test.py");
?>
I have been stuck on this issue for weeks now, everything works separately, but when put together I get the error message, if anyone could help I would appreciate it a lot. Thanks.