In The Beginning
The settlement of Oxford grew up because of the rivers locally. Oxford sits at the confluence of the Cherwell and Thames. This gives it access to drinking water, but also means it's defensible. As its name suggests, here was a good crossing place for cattle, and where people slow to cross a river they may come to need food, shelter, to stop awhile, find it's nice and stay. Or maybe the Thames was as prone to flooding then as now, and they had to wait on the banks. In any case, Oxford began in about 900AD.
In the years before the Normans arrived, the Anglo-Saxons and Danes fought over Oxford city.
By the middle ages, Oxford was a substantial place with some established colleges and plenty of bustle to the town.
The Beginnings of the University
Nobody knows quite how Oxford University originated, though many believe it to have been started by teachers and students expelled from the University of Paris. If that's true, it gives a nice symmetry, as students later drummed out of Oxford are said to have founded Cambridge University.
For many years University College maintained a claim to have been founded by King Alfred, and to have been the original college. Merton also has strong claim to this distinction. To this day University and Merton are kept apart at matriculation ceremonies, as there has been some trouble in the past when more than one Dean has claimed the right, as Dean of the oldest college represented, to make the address.
In any case, Oxford was well established as an academic centre by the end of the twelfth century; a prior of Worcester, writing in 1190, described it as "abounding in men skilled in mystic eloquence, weighing the words of the law, bringing forth from their treasures things new and old."