The first step we recommend when a build works locally but fails on our server (this includes tests tests) is to follow the steps found at:
It is crucial that you try and do this in the /tmp folder (as described in the guide), as that will enable you to run the build in a clean environment.
This should help you pinpoint the source of the issue