Running a python program from a PHP webpage produces RuntimeError

I have a LAMP server set up on my Jetson Nano that can run webpages. I am trying to create a webpage in PHP that can run a python program that turns on an LED at a given duty cycle for a certain number of seconds. Here is the python code being run:

#!/usr/bin/env python

import Jetson.GPIO as GPIO
import sys
from time import sleep


if(len(sys.argv) > 2):
		dc = int(sys.argv[1])
		delay = int(sys.argv[2])

	except Exception as e:

Here is the code for the PHP web page:

<title>PWM Test</title>

$result = exec("python3 programs/ 30 4 2>&1");

echo $result;


The python code runs fine from the shell. However, when I run the php code, the webpage displays the following message:

RuntimeError: The current user does not have permissions set to access the library functionalites. Please configure permissions or use the root user to run this

Here is a screenshot:

I have determined that the problem must lie within the Jetson GPIO library, because when I disable all code relating to GPIO functions, the page displays the word ‘hello’ as I intended.

Any help into this matter would be greatly appreciated

hello tomas,

may I know what’s the actual use-case,
it needs root permission for running GPIO controls.

Hi Jerry,

Sorry for the late reply. How do I determine the use-case?

hello tomas,

just wondering why you need to control LED by webpage.
according to the error messages, it needs root permission for running GPIO controls.
you may try to grant root permission for your webpage implementation.

Hello Jerry,

I’m trying to create a product where the user can run programs without having to log directly into the Jetson, hence why I want to try and control the GPIO through a webpage.

I tried adding www-data (the user running the server) to the ‘gpio’ group, but that didn’t work.

I also tried creating a binary wrapper as outlined here: apache - Execute root commands via PHP - Stack Overflow

Now when I run the compiled c code through php, I get no output. I can run the code through the command line just fine however.

hello tomas,

since there’s default pin configuration, please check developer guide, Configuring the 40-Pin Expansion Header.
please have a try with Jetson-IO tool to simplify the configuration of the I/Os exposed by the 40‑pin expansion header.
after that, you might alter the pin from user-space.

I already did the configuration to use the pin as PWM. Is there something else specifically that I need to do?

hello tomas,

are you able to execute the command, $ python3 programs/ 30 4; via a shell without root permissions?
if not, you should also expect that’s not works by PHP either.

since it needs root permission for running GPIO controls.
it’s not a good idea to allow anyone to control GPIO pins from a webpage.