# add sudoers for www data to execute without pass sudo vi /etc/sudoers www-data ALL=(ALL) NOPASSWD: ALL # execute with sudo shell_exec('python3 script.py')