Well, I would write a simple server which opens a socket, run that as root, and then connect to it with your PHP app.
This way you can keep your server chrooted, and also solved all the complexity problems with sudo and whatnot.
I once wrote something similar with Python, I would post it as an example/guide but I can't seem to find it right now
But this is a fairly common method of doing this sort of stuff so you should be able to find plenty of documentation/examples.
I haven't used sudo in years, so I have little help to offer with that.