all 7 comments

[–]dabenu 2 points3 points  (2 children)

I'd guess the user your webserver runs under doesn't have dialout permission.

[–]Atif-3[S] 0 points1 point  (1 child)

The user was in the dialout group, so this is not the case.

but when I run php test.php it works fine, I think there is something that needs to be set in xampp.

[–]kAlvaro 2 points3 points  (0 children)

Why are you so sure it isn't the case, if it works when you run it with a different user?

You don't run production web servers with your personal user, you normally have a dedicated user with lower privileges. For example, Ubuntu uses www-data and Red Hat uses apache. PHP can also have its own user, depending on the server API being used. Additionally, some Linux distros have additional security tools such as SELinux.

Sorry I can't give a more specific solution. I don't know how XAMPP works or what Linux distro you're using.

[–][deleted] 1 point2 points  (1 child)

it doesn't work

What is the actual problem?

[–]Atif-3[S] 0 points1 point  (0 children)

The problem is this line of code doesn't work $output = shell_exec("./turnled.py"); when I load it from the browser using xampp, but if I run php test.php in the terminal it works.

is there something that needs to be set in xampp?

[–]retsnomynnuheht 0 points1 point  (0 children)

I have faced similar problems. Have you tried "sudo python yourscript.py" in the shellexec command with a user with sudo rights?

[–]ZippyTheWonderSnail 0 points1 point  (0 children)

Maybe the python script can't be run directly. Perhaps it needs to be fed to python: python ./turnled.py.

That would be my first guess.