The Sun was born from a solar nebula, a vast cloud of gas, dust and debris. The birth of the Sun may have occurred 4600 million years ago. Gradually, the core of this huge cloud contracted into a 'proto star'. This proto star shrunk, and became the Sun. The planets and their moons were formed much later, from the leftover matter of the nebula. Many billions of stars were already there, before the birth of the Sun, and many more followed.
The Sun is 149.6 million kilometers away from the Earth, and it takes more than 8 minutes for its rays to reach us. The Sun's gravity keeps all the planets orbiting around it, from flying off in a straight line into outer space.