Yap Ah Loy was born in Guangdong (formerly known as Canton) province, southern China on 14 March 1837. His parents lived in the town of Danshui/Tamsui (Chinese: 淡水; pinyin: Dànshuǐ) in Kwai Yap district, Huizhou prefecture. He was a Hakka of the Fui Chiu clan. Yap Ah Loy left China via Macau for British Malaya in 1854. On his arrival in Malaya, he found the place very different from China. The scenery, with tall coconut and betel palms, and the small Malay houses with atap (nipah thatch) roofs, was a new and fascinating experience to him.
On his arrival at Malacca, Yap Ah Loy was given shelter by one of his clansman called Yap Ket Si. He was then taken to a tin mine in Durian Tunggal, where he stayed for 4 months. At the end of that period he left for Kesang where he found work in the shop of a relative named Yap Ng. He remained there for a year before arrangements were made to send him back to China via Singapore. Misfortune befell him when he lost all his money while waiting for the junk to set sail in Singapore for China. Instead of going back to Malacca he and another of his relatives named Yap Fook traveled on foot to Lukut in Negeri Sembilan.
Yap Ah Loy arrived in Lukut, 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 (Chinese: 劉壬光, 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.
Yap's appointment however was challenged by the "relatives" of Liu, and a group opposed to Yap emerged under the leadership of Chong Chong. There were also constant warfare between two Chinese gangs, the Hakka-dominated Hai San (dominant in Kuala Lumpur) and the Cantonese-dominated Ghee Hin (based mainly in the Kanching and Rawang area), who fought to gain control of tin production in the town. The Selangor Civil War broke out in 1867, and Yap Ah Loy sided with Tunku Kudin. Yap's enemies however sided with Raja Mahdi, and Kuala Lumpur was attacked in 1870. A further attack was attempted, and in 1872, Raja Mahdi's forces led by Syed Mashhor captured Kuala Lumpur, forcing Yap Ah Loy to flee to Klang. Yap attempted to retake Kuala Lumpur, and in March 1873, the Tunku Kudin side, with support from Pahang fighters, defeated Mashhor and recaptured Kuala Lumpur.
Yap's victory at Kuala Lumpur in 1873 proved to be the turning point in the war and left him in a strong political position. Until 1879 he was almost supreme in the interior of the state. As the acknowledged leader of the Chinese community he had been given the powers of a Malay ruling chief by the British except for the right to tax, a restriction he easily evaded.
He achieved a striking post-war recovery in the mining industry and established Kuala Lumpur as the economic centre of the peninsula. Through his control of the tin market, his ownership of local "farms" (monopolies on the sale of items such as opium and exclusive control of activities such as gambling, prostitution, racketeering and loan sharking), and his diverse business interests, he amassed a considerable personal fortune.
In 1879, the first British resident (government advisor) was assigned to Kuala Lumpur, and from that time the power of the Kapitan began to be undermined. None of Yap Ah Loy's successors approached his power and independence of action.
In 1884, Yap Ah Loy began to plan a visit to China. He proposed to appoint Yap Ah Shak and Chow Yuk to manage his property in his absence. For some reasons the plan was postponed. On the 1 September 1884, natural catastrophes caused widespread damage to property in Kuala Lumpur. The violent storm blew down 14 houses and a wing of the newly built Police barracks. The storm also damaged the barrack's residential area and the flagstaff.
In 1868, the third Chinese Kapitan of Kuala Lumpur, Yap Ah Loy, emerged as leader, and became responsible for the survival and growth of this town. During the early times, Kuala Lumpur was beset many problems, including the Selangor Civil War which devastated the town; it was also plagued by diseases and constant fires and floods. Kuala Lumpur was destroyed several times, but each time Yap rebuilt the town. He strove to develop Kuala Lumpur from a small, obscure settlement into a booming mining town. In 1880, the state capital of Selangor was moved from Klang to the more strategically advantageous Kuala Lumpur.
In 1881, a flood swept through the town following a fire which engulfed it earlier. These successive problems destroyed the town's structures of wood and atap (thatching). As a response, Frank Swettenham, the British Resident of Selangor, required that buildings be constructed of brick and tile. Hence, Kapitan Yap Ah Loy bought a sprawling piece of real estate for the setting up of a brick industry which would spur the rebuilding of Kuala Lumpur. This place is the eponymous Brickfields. Hence, destroyed atap buildings were replaced with brick and tiled ones. He restructured the building layout of the town. Many of the new brick buildings mirrored those of shop houses in southern China, characterised by "five foot ways" as well as skilled Chinese carpentry work. This resulted in a distinct eclectic shop house architecture typical to this region. In this developing town, Yap owned a third of all the buildings in Kuala Lumpur, and two third of the urban land east of the Klang River, in addition to his control of the tin mines. Yap Ah Loy also spent a sum of $20,000 to expand road access in the city significantly, linking up tin mines with the city, these roads include the main arterial roads of Ampang Road, Pudu Road and Petaling Street.
As Chinese Kapitan, he was vested with wide powers on par with Malay community leaders. He implemented law reforms and introduced new legal measures. He would also preside over a small claims court. With a police force amounting only 6, he was able to uphold to rule of law. He built a prison which could accommodate 60 prisoners at any time. Kapitan Yap Ah Loy also built Kuala Lumpur's first school and a major tapioca mill in Petaling Street of which the Selangor's Sultan Abdul Samad had an interest.
After Yap's death in 1885, the population of Kuala Lumpur increased greatly due to the construction of a railway line, initiated by Swettenham and completed in 1886, which increased accessibility into the growing town. In 1896, Kuala Lumpur was chosen as the capital of the newly formed Federated Malay States due to its central position. It was however Yap who was responsible keeping Kuala Lumpur viable as a town during its many setbacks in its early years. Although there are no public monuments to Yap, according to the scholar on the Malaysian history J.M. Gullick, "if you seek his memorial remember that you are in Kuala Lumpur."
At the end of 1884, Yap Ah Loy fell ill with bronchitis and an abscess of the left lung. In March 1885, he made little recovery before he died on 15 April 1885 at the age of 47. The doctor examined Yap's body and later confirmed that his death was either due to heart failure or poisoning by the fumes of the charcoal brazier. The doctor also noticed the exceptional brightness of his eyes. He is buried in the large Kwong Tong Cemetery in Kuala Lumpur.
Through his grandson George Yap Swee Fatt, Yap Ah Loy is the ancestor of the Indot family.