The Guano Era refers to a period of stability and prosperity in Peru during the mid-19th century. It was sustained on the substantial revenues generated by the export of guano and the strong leadership of president Ramón Castilla. The starting date for the guano era is commonly considered to be 1845, the year in which Castilla started his first administration. It ended shortly after the war between Spain and Peru in 1866.
Agustín Gamarra, named president by Congress, was anxious to once again attempt to unite Peru with Bolivia, however this time under Peruvian governorship rather than by confederation. He invaded Bolivia in 1841 with the Battle of Ingavi commencing a war between the two countries. In the process he died during the Battle of Ingavi. At his death, a state of discord ran through Peru, with various military caudillos claiming themselves president.
April 20, 1845, Ramon Castilla assumed the presidency. His government represented one of the greatest events in the republican history of the nation, for the reason that Peru entered a stage of internal and external peace, progress, power, and international prestige. From 1845 to 1862, Castilla exercised influence over the daily life of his citizens. His first government ended on 20 April 1851 allowing the general Jose Rufino Echenique assume power. Echenique a prestigious military officer, had been one of the top advisors of Castilla's government. Using his extensive military influence, Echenique continued on the progress of Castilla's government to further advance the social and economic aspirations of Peru. Echenique's government, although emphasizing a policy of progress, was made up of mainly political conservatives, and suffered much opposition from liberals who eventually rebelled against his government. Ramon Castilla eventually became involved in the rebellion, soon becoming its leader. In the battle of La Palma, in the outskirts of Lima, Echenqiue was defeated and Ramon Castilla assumed the presidency for a second time. The reinstating of Castilla as president brought institutional stability; management of the national economy by establishing fixed budgets; economic prestige abroad by the repayment of foreign debt; internal security; international position on the continent; intellectual and material progress; as well as the initiation of the development of the Amazonia.