Born in Louisiana, McLanahan was appointed midshipman 12 December 1839 and passed midshipman 2 July 1845. He served in Preble in the Mediterranean Squadron; in Delaware, Brandywine, and Macedonia in the Brazil, African, and East Indian Squadrons, 1840–45; and in Shark, Portsmouth and Cyane in the Pacific Squadron, 1846–48.
While attached to Cyane, he was one of Lieutenant Charles Heywood's party besieged by Mexican forces at the Siege of San José del Cabo, Baja California, 24 January to 14 February 1848. The small group had been left by Commodore William Shubrick to defend San Jose. He conducted himself in a "gallant, unflinching, and devoted manner" as Heywood's second-in-command, until he was killed by a rifleshot in the neck 11 February 1848.
Two ships have been named USS McLanahan for him.