I think you are going to need to post a code snippet. If you want to find out if it is a permissions issue, You should be able to simply run su - <web-user-id> from root (assuming it is on *nix/Linux), and try your script from the command line again.