I'm currently working on a project, which will dynamically fetch some informations of my job and display them in a html page. To accomplish this i wrote a python script, which will be invoked using a PHP webservice. The script needs to edit some files in order to work.
Basically PHP executes the script using 
 $output = shell_exec('python script.py'); 
The problem is, that if the webservice is called, the script does not have the needed permissions to edit the files.
So the webserver should call the script using something like  $output = shell_exec('sudo python script.py');  
I may need to change the permissions to the project folder but i don't know how.
Some additional informations:
I'm using a raspberry pi 3 with LAMP installation on raspian as webserver
The folder structure is the following:

projectfolder 
| 
- style (containing css)
-script.py
-script2.py
-filetoedit1.txt
-filetoedit2.html
Any help is appreciated!
As suggested by @wpercy you have figure out which user is executing the file. Usually that user is called  www-data !
To find out which user is calling the service use
 ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1  
After you figured out the user you have to change the permission for the folder. That command schould be something like  chown -R www-data:www-data /var/www/html/Projectfolder 
Special thanks to wpercy!
Linux editing privilege over webservice