The first part of the line to be opened was at the southern end, built by the Royal Neapolitan Railway Company and was opened between Naples, Cancello and Caserta on 20 December 1843 and was the second line opened in the Kingdom of the Two Sicilies after the Naples–Portici line opened in 1839. It operated from a terminal at Napoli Porta Nolana, now used by the Circumvesuviana Railway. This line was extended to Capua on 26 May 1844. A branch line was opened from Cancello to Nola in 1846 and extended to Sarno in 1856.
The northern part of the line was opened between a station at Porta Maggiore (southwest of the modern Termini station) and Ciampino on 14 July 1856 as part of the Rome–Frascati line by the Società Pio Latina ("Latin Pius Railway"), a French company named in honour of Pope Pius IX, who had overturned the Vatican's previous opposition to innovations such as railways in the Papal States. This line was extended to the new Roma Termini station on 22 October 1863.
In 1860 the Società Pio Latina and the Società Pio Centrale—the builder of the Rome–Civitavecchia railway, opened in 1859—combined to form the Società per le strade ferrate romane ("Roman Railway Company"), which then absorbed the Royal Neapolitan Railway Company. It opened an 80 kilometres (50 mi) section from Roma Termini to Ceprano–Falvaterra (including the Porta Maggiore–Ciampino section) on 1 December 1862. The 42 kilometres (26 mi) Capua–Tora–Presenzano section had been opened on 14 October 1861 and the final 52 kilometres (32 mi) section between Ceprano–Falvaterra and Tora–Presenzano was opened on 25 February 1863.
Problems with the Rome–Naples line via Cassino led to proposals for the construction of a new line nearer the coast as early as 1871. When the Papal States planned the Cassino line, it was not designed just as a direct connection with Naples, but also was intended to connect with smaller localities on the way. Partly as a result, it had a tortuous route which, especially in the valley of the Sacco River, was subject to frequent disruption by floods and landslides. The old line was built to the avoid the coastal route through the Pontine Marshes, which was still swampy and malarial. As a result, its route is hilly and in parts mountainous, creating problems for the under-powered steam locomotives of the period.