There is a tendency to view planet Earth as created to be a solid platform for life. But that is not the case.
The planet initially was most inhospitable and badly suited for higher life forms. It didn't have a breathable atmosphere, and many of the properties of our planet we take for granted are in fact the product of an extended period of chemical processes - with the eventual introduction of "primitive" life forms, i.e. single celled; bacteria.
Instead of me trying to explain things, it is better that I provide links for sources to speak for themselves. I learn a little more myself in the process, I often know what to look for but may be ignorant about the details. Would be funny if it wasn't so; a non-professional can't be expected to know the details of all the fields upon which all the scientific exploration of the fascinating four billion years of planet history rest.
I first learned about an got interested in this particular field when I read books by James_Lovelock
I don't think we need take the 'Gaia hypothesis' too seriously. I don't think it is intended as anything but a metaphor to convey the concept of interdependence; life on the planet is a veritable "machine" where all the parts, even the most humble and seemingly insignificant plays a crucial role. And the planet itself is an active partner as well. We live on a habitable planet, we have a habitable planet because there is life on the planet. Without life, the planet would not be habitable! At least not for higher life forms, say, like the one we belong to...