The script in ** Python ** is run from ** PHP **. The script runs normally, but reaching the lines of launch ** vncserver ** - it cannot run it:
#!/usr/bin/env python3.8
# -*- coding: UTF-8 -*-
import time
import requests
from datetime import datetime
from pymongo import MongoClient
from multiprocessing import Pool
import json
import math
import subprocess
import os
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
.
.
.
## VNC Display checks
# Configure DISPLAY variable to VNC
os.environ["DISPLAY"] = cfg["vnc_display"]
if os.system("xhost >& /dev/null"):
print("WARNING: No VNC display opened under %s. Running VNC Server and trying again" % (os.environ["DISPLAY"]))
os.system("vncserver %s" % (os.environ["DISPLAY"]))
time.sleep(5)
if os.system("xhost >& /dev/null"):
print("ERROR: No VNC display opened under %s. Cannot continue" % (os.environ["DISPLAY"]))
return
.
.
.
if __name__ == "__main__":
command_line_runner()
stops work and displays a message:
vncserver: The HOME environment variable is not set
No VNC display opened under :1.
Running VNC Server and trying again.
ERROR: No VNC display opened under :1.
Cannot continue.
As I understand it, ** vncserver ** does not want to start with user privileges ** Apache **, but only from under the user - the error is related to execution rights. Because if you run the script directly, on the command line, on behalf of the user - there are no errors and everything works fine. I think I need to teach somehow the script to work correctly with ** Apache ** privileges, but I don’t know how to do it. Please suggest solutions. Thank.
Added the following lines of code and everything started working as needed:
.
.
.
from os.path import expanduser
HOME = expanduser("~")
.
.
.
os.environ["HOME"] = HOME
Helped tips: DavidPostill, Anaksunaman
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments