Thanks everyone. With your ideas and hints I was able to fix this.
1. I created a VirtualHost in apache2.
2. I had the permissions set to 755 for the directory to write to. Changed this to 755.
3. Instead of calling with 'backtics' I used system($command).
Again, thanks, R