In astronomy, this question is formally known as the "origin of the solar system". Although this question is difficult to answer, scientists have reached a relatively consistent understanding of the age of the solar system and the chemical composition of the planets, and have generally adopted the "modern nebular theory" of the origin of the solar system.
In history, the first "nebular theory" of the origin of the solar system was proposed by German philosopher Kant in 1755, but it did not attract much attention at that time. In 1796, French astronomer Laplace proposed a more reasonable nebular theory of the origin of the solar system in his book "The System of the World". Later, these two theories were often collectively referred to as the "Kant-Laplace nebular theory".
The modern theory of the origin of the solar system has developed some basic arguments of the early nebular theory. Its main content is: (1) About 5 billion years ago, a huge gas-dust cloud, namely the "solar nebula", contracted under its own gravity; (2) The solar nebula continued to contract and gradually became flatter due to the centrifugal force of its rotation. The large central mass would later become the sun, and some smaller masses on the periphery would become planets; (3) Dust particles played the role of coagulation nuclei. Material masses collided and coalesced with each other, gradually growing into "protoplanets" as large as the moon; (4) The forming sun produced a strong "stellar wind", "blowing" the nebular gas away into the distance; (5) The protoplanets continued to collide and grow; (6) After hundreds of millions of years, the eight planets orbiting the sun in a nearly circular orbit were finally formed. Thus, the main parts of our solar system were born.

