Trying to make a build server, getting a permission error

I have a VPS running Ubuntu and Apache2, PHP 8.3, and Python3.12

I installed PlatformIO using the https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py script

it currently lives in “/root/.platformio/penv/bin/pio” with a symlink in “/usr/local/bin/pio”.

I have a Python script that’s written to git-clone a repo and then do a build with “pio” launched with the subprocess.POpen() function

It throws an exception stating permission error

I try the same thing with PHP and exec() or shell_exec() and I get the same thing, permission denied error

Apache and PHP would be executing using the user “www-data”. PlatformIO was installed as root

I’ve made a new group called “shrewusers” and added both root and www-data to it and then changed the group ownership of “/root/.platformio/penv/bin/pio” to be “shrewusers”. I’ve also used “sudo chmod +x /root/.platformio/penv/bin/pio” to add execute permissions

I still get a permission denied error

What is wrong? How can I get my web server to actually run pio?

Thanks

Progress, installed PIO into a virtual environment and gave it all to the www-data user and now it executes but throws another permission denied exception internally, at least now there’s a stack trace

Build Failed, code 1
PermissionError: Traceback (most recent call last):
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/__main__.py", line 103, in main
    cli()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/cli.py", line 85, in invoke
    return super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/click/core.py", line 1685, in invoke
    super().invoke(ctx)
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/__main__.py", line 56, in cli
    maintenance.on_cmd_start(ctx, caller)
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/maintenance.py", line 35, in on_cmd_start
    telemetry.on_cmd_start(ctx)
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 173, in on_cmd_start
    log_command(cmd_ctx)
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 186, in log_command
    log_event("cmd_run", params)
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 168, in log_event
    TelemetryLogger().log_event(name, params, instant_sending=instant_sending)
    ^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/util.py", line 132, in get_instance
    _instances[cls] = cls(*args, **kwargs)
                      ^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 78, in __init__
    self._http_session = HTTPSession()
                         ^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/http.py", line 52, in __init__
    self.headers.update({"User-Agent": app.get_user_agent()})
                                       ^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 277, in get_user_agent
    if not get_setting("enable_telemetry"):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 208, in get_setting
    with State() as state:
         ^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 88, in __init__
    self.path = resolve_state_path("core_dir", "appstate.json")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 79, in resolve_state_path
    os.makedirs(state_dir)
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/var/www/.platformio'
============================================================
An unexpected error occurred. Further steps:
* Verify that you have the latest version of PlatformIO using
  `python -m pip install -U platformio` command
* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq/index.html
* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues
============================================================
Traceback (most recent call last):
  File "/var/www/private/piovenv/piovenv/bin/pio", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/__main__.py", line 134, in main
    maintenance.on_platformio_exit()
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/maintenance.py", line 65, in on_platformio_exit
    telemetry.on_exit()
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 177, in on_exit
    TelemetryLogger().send()
    ^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/util.py", line 132, in get_instance
    _instances[cls] = cls(*args, **kwargs)
                      ^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 78, in __init__
    self._http_session = HTTPSession()
                         ^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/http.py", line 52, in __init__
    self.headers.update({"User-Agent": app.get_user_agent()})
                                       ^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 277, in get_user_agent
    if not get_setting("enable_telemetry"):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 208, in get_setting
    with State() as state:
         ^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 88, in __init__
    self.path = resolve_state_path("core_dir", "appstate.json")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 79, in resolve_state_path
    os.makedirs(state_dir)
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/var/www/.platformio'
Exception ignored in atexit callback: <function _finalize at 0x767d8bd73e20>
Traceback (most recent call last):
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 313, in _finalize
    telemetry = TelemetryLogger()
                ^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/util.py", line 132, in get_instance
    _instances[cls] = cls(*args, **kwargs)
                      ^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/telemetry.py", line 78, in __init__
    self._http_session = HTTPSession()
                         ^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/http.py", line 52, in __init__
    self.headers.update({"User-Agent": app.get_user_agent()})
                                       ^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 277, in get_user_agent
    if not get_setting("enable_telemetry"):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 208, in get_setting
    with State() as state:
         ^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 88, in __init__
    self.path = resolve_state_path("core_dir", "appstate.json")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/private/piovenv/piovenv/lib/python3.12/site-packages/platformio/app.py", line 79, in resolve_state_path
    os.makedirs(state_dir)
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/var/www/.platformio'

Is this because it has no permissions in creating a directory at “/var/www/.platformio”? why is it doing that? it makes no sense according to where the virtual environment is and where the repository is.

I might be dumb, “/var/www” is the home directory of user “www-data” so that’s why pio was trying to make a directory there.

I did some chmod commands to give www-data permissions to write to /var/www and everything is fixed, my project builds

I’m pretty proud of it, a combination of HTML and PHP and Javascript lets the user configure a build, it’s passed to a PHP launcher that communicates with a Python+Flask build scheduler, so if the build is queued, the client gets a busy message and the Ajax will let the client know when it’s done building