Ra was the solar deity, bringer of light, and thus the upholder of Ma'at.
Also, comparable hostile snakes as enemies of the sun god existed under other names (in the Pyramid Texts and Coffin Texts) already before the name Apep occurred.