Fanning, the son of American businessman John Fanning and Peruvian lady Micaela Garcia, was born in Lambayeque in 1824. He joined the Peruvian Navy at age 15 and received his first commission as junior officer of the warship "Libertad". He fought as Corvette Captain during the 1866 war with Spain, and from April to September 1879 was posted in Arica.