By observing other young stars, we believe that a solar system begins with a collapsing cloud that contracts into a flattened disk.  Out of this disk, dust grains grew progressively larger, sticking together to form larger bodies that over millions of years form kilometer-sized bodies.  The gravity of these young planets would attract more and more matter over time until you ended up with planets.