It was being recorded in the book form in the time of the prophet. People made their own copied and others committed it to their memories. at the demise of the prophet, a lot many people have their copies. All this has been recorded in Ahadith and historical traditions. you can consult a very well researched book of Dr Shehzad Saleem, The History of Quran. See this hadith
عن ابن عمر رضي الله عنهما قال: “نهى رسول الله صلى الله عليه وسلم أن يسافر بالقرآن إلى أرض العدو” ((متفق عليه)).
The Messenger of Allah (ﷺ) forbade travelling to the land of the enemy carrying the Qur’an.
Reference : Riyad as-Salihin 1794
In-book reference : Book 17, Hadith 284