This doesn't make sense. A 401 error is issued by the Web server to indicate you don't have access to the requested resource. In this case the resource should NOT be your shell script, but rather the PHP page that includes the invocation. A permissions problem with the script should generate a complaint from PHP, not from the Web server.
Please post an example showing HOW you are invoking the external program.