The coral skeleton harbours a diverse community of bacteria and microeukaryotes exposed to light, O2 and pH gradients, but how such physicochemical gradients affect the coral skeleton microbiome remains unclear. In this study, we employed chemical imaging of O2 and pH, hyperspectral reflectance imaging and spatially resolved taxonomic and inferred functional microbiome characterization to explore links between the skeleton microenvironment and microbiome in the reef-building corals Porites lutea and Paragoniastrea benhami. The physicochemical environment was more stable in the deep skeleton, and the diversity and evenness of the bacterial community increased with skeletal depth, suggesting that the microbiome was stratified along the physicochemical gradients. The bulk of the coral skeleton was in a low O2 habitat, whereas pH varied from pH 6–9 with depth. Physicochemical gradients of O2 and pH of the coral skeleton explained the β-diversity of the bacterial communities, and skeletal layers that showed O2 peaks had a higher relative abundance of endolithic algae, reflecting a link between the abiotic environment and the microbiome composition. Our study links the physicochemical, microbial and functional landscapes of the coral skeleton and provides new insights into the involvement of skeletal microbes in the coral holobiont metabolism.