Yap Ah Loy arrived in Lukut, then part of Selangor (now in the state of Negeri Sembilan), in 1856 at the age of 19. He spent his early years in the peninsula as a miner and petty trader, but in 1862 his fortunes improved when his friend Liu Ngim Kong (, Pinyin: Liú Rènguāng) succeeded Hiew Siew to become the second Kapitan Cina of Kuala Lumpur, a position not only of leadership within the Chinese community but also of liaison with the Malay political system and, after British intervention in 1874, with British officials as well. He served as Liu's trusted lieutenant and became the third Kapitan Cina of Kuala Lumpur after Liu's death in 1869, after which he began to put together a sound administration and a strong fighting force.