Spain had controlled the Philippines, legally at least, ever since Magellan "discovered" the chain of islands in 1521. Actual colonization of the islands started in 1565. By 1571, the Spaniards had reached Luzon (the northernmost and now main island of the country). There, they set up Manila which is now the capital.
The Filipinos fought Spanish rule late in the 1800s. They did this because they had heard of the rebellions against Spanish rule in Latin America and because they were influenced by Enlightenment ideas that people should govern themselves.
Spain established their first settlement in Philippines in 1565, and then expanded their presence and power there. By 1572 they gained control of many of the islands in the Philippines. During this period they wee also able to prevent any other country to gain a foothold there. Starting from that time,and up to 1898, Spain ruled over Philippines without break till they ceded the country to USA as a part of the treaty following Spanish-American war.
However the Spanish rule over Philippines was not entirely without opposition from the local Filipino people, particularly the people who practiced Muslim faith. There were almost continuous warfare between Spaniards and Muslims people of Mindanao and Sulu throughout the Spanish colonial rule.
Also oppressive practices of Spanish rule that furthered economic interests of Spain at the cost of Filipinos created resentment among local people. First major resistance occurred in 1822 in the form of revolt by Filipino workers against harsh treatment by government and factory bosses. This resulted in weakening of tobacco industry for many years.
The intensity of the Filipino resistance increased with the increasing exposure to ideas of freedom and equality which were sweeping the entire world as a result of increasing interaction between people of different regions of the world. Spread of such Ideas also created support for the Filipino cause among some liberal Spaniards.