The dynamics of bubbles inertially collapsing in water near solid objects have been the subject of numerous studies in the context of cavitation erosion. While non-spherical bubble collapse, re-entrant jet dynamics and emitted shock waves have received significant interest, less is known about the temperatures thereby produced and their possible connection to damage. In this article, we use highly resolved numerical simulations of a single bubble inertially collapsing near a rigid surface to measure the temperatures produced in the fluid and estimate those in the solid, as well as to identify the responsible mechanisms. In particular, we find that elevated temperatures along the wall can be produced by one of two mechanisms, depending on the initial stand-off distance of the bubble from the wall and the driving pressure: for bubbles initially far from the wall, the shock generated by the bubble collapse is the source of the high temperature, while bubbles starting initially closer migrate towards the wall and eventually come into contact with it. A scaling is introduced to describe the maximum fluid temperature along the wall as a function of the initial stand-off distance and driving pressure. To predict the temperature of the solid, we develop a semianalytical heat transfer model, which supports recent experimental observations that elevated temperatures achieved during collapse could play a role in cavitation damage to soft heat-sensitive materials.