Solar panels are typically attached to the roof using mounting brackets that are secured to the roof rafters. Rails are then attached to these brackets, and the panels are clamped onto the rails. The specific method can vary depending on the type of roof and mounting system.