I think man worshiped and gave thanks to the sun originally, as back then there were no scientific advancements. All we knew came from our assumptions and our imaginations. The sun gave us light so we could see, so we didn't have to hide from predators, it made the plants grow, it provided us with warmth and food.
Over time i think things changed, as people began to enslave mass populations, in order to keep them working and not killing themselves, a promise of an afterlife would seem very temping to them, especially if it says that killing yourself would lead you to eternal damnation, and doing what you are told will result in a blissful afterlife.
It is easy to see that here in the 21st century, if not back then... that people... and even governments use religion to further their own agenda, and to take advantage of peoples dreams, hopes... and fears.