I need to be able to modify my openvpn auth file via a php script. I have made my http user a no-pass sudoer, as this machine is only available within my home network.
Instead of running an entire shell process as root, which is arguably unsafe, you can run the copy as root:
(with bash):
sudo cp <(echo "$username") /etc/openvpn/auth.txt
(should work with any shell):
echo "$username" | sudo dd of=/etc/openvpn/auth.txt