According to this Wikipedia entry:
In some of the Scooby-Doo series, Shaggy is born in Coolsville, Ohio. When he was old enough to go to school he adopted Scooby–Doo from the Knittingham Puppy Farm. Later on, he met Fred Jones, Daphne Blake, and Velma Dinkley. They became friends and they decided to be a team named Mystery Inc. (short for Mystery Incorporated).
This LiveJournal page presents a "unified history" and says:
Only a few months after Howdy's birth, Scooby met his platonic soulmate, Norville "Shaggy" Rogers. Mrs. Knittingham, who owned the farm, was good friends with Shaggy's mother. The Rogers family came to visit the woman, and that's when the year-old Scooby and three-year-old Shaggy connected for the first time. Shaggy came over often to see Scooby, and Mumsy, Dadsy, and Mrs. Knittingham promised that when Scooby was old enough, if he wanted to be Shaggy's pet, he could be.
By the time Scooby was two, his parents had inherited Doo Manor, the home that had been passed down through the years. Scooby's grandpa had gotten to the point where he couldn't care for himself, or the old house, so the Doos packed up their pups and moved from Mrs. Knittingham's farm into the old house, along with Scooby's brainy (and slightly creepy) Uncle Horton. By that time, Scooby had also gained a baby sister, Ruby. Only a few weeks after moving into the house, Scooby pleaded with his parents, asking if he could live with Shaggy, and they agreed. Shaggy was overjoyed, and even allowed Scooby to have his own doghouse built.
This seems to be based on the wildly inconsistent histories provided through numerous TV shows (and perhaps other media), although it appears that the relation between Scooby and Shaggy consists throughout.