Read up on sudo to know what it does and why. Mainly since security is one of the issues, and the other is risking to lock yourself out form using the sudo command.
You will need to edit /etc/sudoers (don't just vi it, use visudo for syntax checking or you may not be able to run sudo again) and add something like
Cmnd_Alias STUFF_WEBSERVER_CAN_DO = /bin/somestuff, /sbin/someotherstuff
webserverusername ALL=(ALL) NOPASSWD: STUFF_WEBSERVER_CAN_DO
Needless to say, NOPASSWD: ALL is a bad idea.
Then
exec('sudo -u webserverusername /bin/somestuff');