How to fix the error "vncserver: The HOME environment variable is not set" - run a Python script from PHP on behalf of the user?

Combat Unit

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.

Combat Unit

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to run python script from php on xamp?

From Dev

how to run python script from php on xamp?

From Dev

How to run script as php user

From Dev

how to run a user command from a script

From Dev

Run compiled python script from PHP

From Dev

How to run bundle from PHP script

From Dev

Run Python script with PHP

From Dev

How to Run a Python Script from a Rails Application?

From Dev

How to run a Python Script from Deno?

From Dev

How to run a shell script as different user with PHP on Nginx?

From Dev

How to fix this 2 issue by php (edit user from admin)?

From Dev

PHP Fake Mailer Script says 'via' or 'on behalf of'

From Dev

PHP Fake Mailer Script says 'via' or 'on behalf of'

From Dev

How to run a script from apache user in non owned folder?

From Dev

How to run python script as non-root user on startup

From Dev

How server should authenticate on behalf of iOS user?

From Dev

How to execute a command on behalf of a user if login is denied

From Dev

How to execute a command on behalf of a user if login is denied

From Dev

How server should authenticate on behalf of iOS user?

From Dev

How to connect Azure ad on behalf of user with appid?

From Dev

Python script calling `arp` produces error when run from crontab

From Dev

How to fix PHP Fatal error: Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined

From Dev

Run bash script from php

From Dev

Run bash script from php

From Dev

How to run executable from PHP website as a specific Windows user?

From Dev

How to run executable from PHP website as a specific Windows user?

From Dev

How can I to run php script from powershell-commandline?

From Dev

c9 - How to run php function from script tag?

From Dev

How to run php script from android's browser?

Related Related

  1. 1

    how to run python script from php on xamp?

  2. 2

    how to run python script from php on xamp?

  3. 3

    How to run script as php user

  4. 4

    how to run a user command from a script

  5. 5

    Run compiled python script from PHP

  6. 6

    How to run bundle from PHP script

  7. 7

    Run Python script with PHP

  8. 8

    How to Run a Python Script from a Rails Application?

  9. 9

    How to run a Python Script from Deno?

  10. 10

    How to run a shell script as different user with PHP on Nginx?

  11. 11

    How to fix this 2 issue by php (edit user from admin)?

  12. 12

    PHP Fake Mailer Script says 'via' or 'on behalf of'

  13. 13

    PHP Fake Mailer Script says 'via' or 'on behalf of'

  14. 14

    How to run a script from apache user in non owned folder?

  15. 15

    How to run python script as non-root user on startup

  16. 16

    How server should authenticate on behalf of iOS user?

  17. 17

    How to execute a command on behalf of a user if login is denied

  18. 18

    How to execute a command on behalf of a user if login is denied

  19. 19

    How server should authenticate on behalf of iOS user?

  20. 20

    How to connect Azure ad on behalf of user with appid?

  21. 21

    Python script calling `arp` produces error when run from crontab

  22. 22

    How to fix PHP Fatal error: Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined

  23. 23

    Run bash script from php

  24. 24

    Run bash script from php

  25. 25

    How to run executable from PHP website as a specific Windows user?

  26. 26

    How to run executable from PHP website as a specific Windows user?

  27. 27

    How can I to run php script from powershell-commandline?

  28. 28

    c9 - How to run php function from script tag?

  29. 29

    How to run php script from android's browser?

HotTag

Archive