Before the war, Peru was involved in a civil war between north and south. Marshal Andrés de Santa Cruz, President of Bolivia, lent his support to the south and, once he north was finally conquered, he established the Republics of North Peru and South Peru. To top it all, he decided to create a confederation with the three nations, with him as Supreme Protector.
Chile, instigated by Diego Portales, saw the confederation as a commercial threat, and a failed expedition of former president Ramón Freire to seize power as Santa Cruzs plan to interfere with Chiles internal politics. But even though the war was declared, nobody in the country really cared.
And then Portales was killed by some soldiers unhappy with his military purges and political ways. The assassination was seen as another move of Santa Cruz to throw Chile into chaos, making the war acceptable to the people.
The first expedition to the Peru was an absolute fiasco and ended with the Treaty of Paucarpata, leaving things almost the same as it started.
Back in Chile, the failure was so scandalous that the government sent a second expedition to Peru. This one was more successful and the military defeats and growing opposition in Bolivia forced Santa Cruz to flee, ending the war and the confederation. Bolivia and Peru were two states again and Peru was unified once again.
Peru and Bolivia kept in war for some time, but that's part of another story.
If you're searching for the war that involved the Confederate States of America, that would be The American Civil War.