It is only with the first election of Ramon Castilla in 1845 that the Republic of Peru is a relative inner peace and can organize their political and economic life. Castilla corresponds to abolish slavery and the death penalty. Establishes policies to promote extraction and export of natural fertilizers (guano islands) that initiate an era of prosperity in the country. The first railways and gas lighting arriving in Peru in this period. During his second government promulgated the Constitutions of 1856 (Liberal) and the Constitution of 1860 (Conservative), reorganized the postal services and public career.
View: Peruvian Civil War 1856-1858
In 1864 a Spanish expedition occupied the Chincha Islands (guano-producing) and unleash a major international incident in the domestic political consequences of Peru, which led to a coup against President Pezet, the dictatorship of Mariano Ignacio Prado and the declaration of war on Spain. After the battle of Callao (May 2, 1866), the Spanish fleet retires in Peru.
The government of Jose Balta were numerous infrastructure projects (construction of Central Railway), although he perceived as the first signs of excessive government spending. At the end of his government, the election for the first time a civilian president, Manuel Pardo y Lavalle, led a military uprising that ended in the murder of Balta and the furious reaction of the population of Lima (who executed the usurpers). Thus ends what he called Prime Jorge Basadre Militarism. Pardo implemented major reforms of a liberal in the state organization. However, the main source of government resources, guano, overexploited, depleted and began an economic crisis was inevitable that the successor to Pardo, the aging Mariano Ignacio Prado had to face, in the midst of a virtual state bankruptcy.
It is in these circumstances when there is the territorial dispute between Chile and Bolivia. Obligated to help the latter by a secret treaty, Peru went to war in 1879. The Pacific War, which ended with the occupation of Lima between 1881 and 1883, and the territorial loss of the province of Tarapaca and Arica to Chile, created deep wounds in Peru. Some of the major icons of Peruvian history are from this period (Miguel Grau, Francisco Bolognesi, Andrés Avelino Cáceres). After a period of political instability after the defeat (governments Miguel Iglesias and the aforementioned Cáceres) comes Piérola Nicholas government in 1895 the Democratic Party.