Foundations of relative homological algebra