It is commonly quoted during discourses on vAlmIki rAmAyana, but I cannot find any verse in vAlmIki rAmAyana that contains this often quoted verse, which means 'without a son you have no chance of getting into heaven'. Online sites say it is said in 'shruti'. But what text of Shruti does it appear in exactly?
अपुत्रस्य गतिर्नास्ति स्वर्गो नैव च नैव च ।
येन केनाप्युपायेन कार्यँ जन्म सुतस्य हि ।।
There is no place for sonless person , the heaven is not for him. One must have a son by any means whatsoever. - Garuda Purana.
There is no prospect in the after birth of the sonless; never, never will Heaven be his. Without son, there is none other who can be of help in the next world. - Devi Bhagavata Purana
looking at the above shloka it is quite clear that it is from puranas and much different in composition than that of the style of mantras found in Vedas i.e. shruti. So it is highly unlikely that this shloka is present in shruti. And we can say that it belongs to puranas or later traditions than shruti. i.e. post panini.
The part of Vālmīki Rāmāyaṇa where the commentators cite that verse is probably this:
tam ca rājā daśaratho yaśas kāmaḥ kṛtāṃliḥ |
ṛṣyaśṛṅgam dvija śreṣṭham varayiṣyati dharmavit || 1-11-8
yajñārtham prasavārtham ca svargārtham ca nareśvaraḥ |
labhate ca sa tam kāmam dvija mukhyāt viśāṃpatiḥ || 1-11-9
That king, the desirer of glory, the knower of virtue and the lord of people, namely Dasharatha will be requesting that best Brahman Rishyasringa with his palms adjoined in supplication for the conduct of ritual, for progeny and even for his heavenly abodes, and that king of all the quarters of earth will accomplish those desires from that eminent Brahman Rishyasringa. [1-11-8,9]
Commentary from the same website says:
Heavenly abodes are dependent on begetting sons:
aputrasya gatir naasti svargo naivaca naivaca
There is no way out [in other worlds] for those without sons... shruti scripture. Hence the request of Dasharatha is that way.
The śruti equivalent of this can be found in the Legend of Śunaḥśepa from Aitareya Brāhmaṇa (Ṛgveda) where Nārada says there's no place in heaven for men who don't have sons:
PAÑCIKĀ VII ADHYĀYA III
The Legend of Śunaḥśepa.
vii. 13 (xxxiii. 1). Hariścandra Vaidhasa Aikṣvāka was the son of a king; a hundred wives were his, but he had no son from them. In his house dwelt Parvata and Nārada; he asked Nārada:
Since now men desire a son,
Both those that have and those that have not knowledge
What doth a man gain by a son?
Tell me that, O Narada.
He, asked in one verse, replied in ten:
A debt he payeth in him,
And immortality he attaineth,
That father who seeth the face
Of a son born living.
The delights in the earth,
The delights in the fire,
The delights in the waters of living beings,
Greater than these is that of a father in a son.
By means of a son have fathers ever
Passed over the deep darkness;
The self is born from the self
The (son) is (a ship), well-found, to ferry over.
What is the use of dirt, what of the goat-skin?
What of long hair, and what of fervour?
Seek a son, O Brahmans,
This is the world's advice.
Food is breath, clothing a protection,
Gold an ornament, cattle lead to marriage,
A wife is a comrade, a daughter a misery, (sakhā ha jāyā kṛpaṇaṃ ha duhitā)
And a son a light in the highest heaven. (jyotir ha putraḥ parame vyoman)
The father entereth the wife,
Having become a germ (he entereth) the mother,
In her becoming renewed,
He is born in the tenth month.
A wife hath her name of wife,
Since in her he is born again
He is productive, she productive,
The seed is placed here.
The gods and the seers
Brought her together as great brilliance;
The gods said to men
This is your mother again.
A sonless one cannot attain heaven, (nāputrasya loko 'stīti)
All the beasts know this;
Therefore a son his mother
And his sister mounteth.
This is the broad and auspicious path
Along which men with sons fare free from sorrow;
On it beasts and herds gaze
For it they unite even with a mother.
Thus he told him.