My php script:
www-data ALL=NOPASSWD: /path/to/script.sh
If your system has selinux or some other policy-based access control engine enabled, your web server process will be running under a constrained context which limits rights further. Verify whether you have selinux enabled.
Provide the full path to
sudo. While your shell may have it in its path, perhaps your web server does not.