Script in Python via PHP

1

I am trying to call a script done in Python via browser with PHP. This script has only one command that serves to turn off my Raspberry Pi.

PHP looks like this:

<?php
 exec('sudo python /home/pi/Documents/Programa/Script.py');
?>

Python script:

import os
os.system('sudo shutdown -r now')

I ran the program in Python and PHP (via terminal) separately and the two are working properly. Only when I call in the browser that it does not execute. I know I have to change permissions on folders and files, but I'm not sure exactly what directories I have to give these permissions because I'm a beginner in the PHP and Linux world. I've already looked at some other website means to do this.

asked by anonymous 20.09.2018 / 20:00

1 answer

2

Php is not allowed to shut down the computer. It runs with an internal service user, (usually www-data), and that user is not allowed to run sudo .

When you run with your user, in the terminal, it works, because your user is allowed to use sudo , but when php is run the command, it will fail because the user running the php server does not have this permission.

    
21.09.2018 / 00:24