After independence Peru had a hard time with the transition from the feudal society imposed by the Spanish Viceroyalty to a self-governed democratic Republic.
With Simon Bolivar leaving Peru in 1826 and his stabilizing and moderate influence gone, the rivalry of different forces, including former military leaders (so-called caudillos) who had gained prominence in the struggle for independence, and liberal / conservative parties without realistic and future-orientated visions, led to political turmoil and instability in the following years. The lack of economic resources and trade slowed down the country further. Additionally, Peru and its neighbors engaged in short-lasting alliances and sporadic territorial disputes which weren’t helpful in consolidating Peru’s political and economic situation.
President Ramon Castilla (1845 - 1851)
However, when Ramon Castilla, a mestizo (a person of a combined white / Spanish and indigenous Peruvian ancestry) caudillo became president of Peru in 1845, the country was at the beginning of a boom based on the exploitation of guano deposits along the coast and offshore islands (guano = droppings of seabirds - an effective fertilizer and gunpowder ingredient).
For decades taxes on this industry were the principal source of government revenue, allowing a modernization of Peru: in 1850 a railroad line between Lima and Callao was completed. Others along the beach up to Chorrillos followed and five years later Lima started using gas lighting. During his two presidencies (1845-1851 and 1855-1862) Castillo as well implemented a state primary and secondary education system, abolished slavery, paved the way for thousands of Chinese immigrants to come to the country and work on the coastal haciendas and brought a new postal system and a new constitution on the way.
However, the political turmoil continued with internal rebellions, territorial disputes with neighboring countries and last Spanish attempts to regain power not only disrupted the economic development but drained Peru’s treasury heavily.
President Manuel Prado (1872 - 1876)
In 1871, unhappy with the military rule Manuel Prado, part of Lima’s old established nobility and Minister of Finances (1865 - 1867) and Mayor of Lima (1869 - 1870), founded the Partido Civil, the most important political party in the 2nd half of the 19th century representing wealthy traders, plantation owners and business people who profited from the guano boom and considered the ruling military as corrupt and incapable of leading the country into a new era of international trade, business and financial relations.
A year later he became the first civilian president of Peru and immediately implemented a costly internal development program which included among others the construction of a railroad system across the Andes mountains and the establishment of higher education institutions increasing the national debt even further.
In 1873, the Treaty of Defensive Alliance was signed. The treaty was a secret pact between Peru and Bolivia establishing a mutual defense alliance and seeking to protect the national security of both countries and the regional balance of power by containing the Chilean expansion policy, which was fueled by its economic ambitions over the rich mineral resources (saltpeter) of the Atacama Desert, back then part of Bolivia and Peru. Signing this treaty and later declaring its alliance with Bolivia would lead Peru into the next devastating catastrophe.