Very simple situation and very simple fix.
Whether you are using apache of php-fpm, you need to grant your web server with sudo privilege. This can be done by adding the following line to /etc/sudoers file:
apache ALL=NOPASSWD: /usr/local/bin/my_command.sh
Done !