If your webserver runs as the www-data
user user:
www-data ALL=(ALL:ALL) NOPASSWD: /path/to/your/script
If not, replace www-data
by your web server's user name.
In php don't miss to prepend your command line with sudo
:
exec('sudo /path/to/your/script');