Apply Travis fixes to the 0.5 branch

This is just the same commits as PR #1186