Ibn Abbas (may Allah be pleased with him) related at length how Ibrahim (peace be upon him) brought Hajar and her infant son Isma'il to a barren valley, left them near the site of the House, and prayed to Allah. At that time the site was a raised mound. An angel later told Hajar not to fear being lost, for "here is the House of Allah, which this boy and his father will build" (Sahih al-Bukhari 3364).
When Isma'il had grown up, Ibrahim told him: "Allah has commanded me to build a house here." The two raised the foundations, with Isma'il bringing the stones and Ibrahim building, and Ibrahim stood on a stone as the walls rose higher. As they built, they said: "Our Lord, accept this from us. You are the Hearing, the Knowing" (Sahih al-Bukhari 3364). The Quran recalls the same moment: "And when Ibrahim was raising the foundations of the House, and Isma'il [with him, saying]: Our Lord, accept this from us. Indeed, You are the Hearing, the Knowing" (Quran 2:127).
The Quran also says that Allah "designated for Ibrahim the site of the House" and commanded: "Do not associate anything with Me, and purify My House for those who perform tawaf, those who stand in prayer, and those who bow and prostrate" (Quran 22:26). Some scholars say that "raising the foundations" means raising walls on earlier foundations, and others say that Ibrahim built it from the beginning. Accounts that Adam or the angels built it earlier come from reports without an authentic chain, so nothing definite can be said about them.