Raja Ali Haji was born in Selangor (although some sources stated that he was born in Penyengat) in 1808 or 1809, and was the son of Raja Ahmad, who was titled Engku Haji Tua after accomplishing the pilgrimage to Mecca. He was the grandson of Raja Ali Haji Fisabilillah (the brother of Raja Lumu, the first Sultan of Selangor). Fisabilillah was a scion of the royal house of Riau, who were descended from Bugis warriors who came to the region in the 18th century. His mother, Encik Hamidah binti Malik was a cousin of her father and also of Bugis descent. Raji Ali Haji soon relocated to Penyengat as an infant, where he grew up and received his education there.
Most sources stated that Raja Ali Haji died in 1872 at Penyengat Island in Riau, but the date of his death was being debated as scattered evidences surfaced to oppose this claim. Among the best-known evidences was a letter written in 1872 when Raja Ali Haji wrote a letter to Herman Von De Wall, a Dutch cultural expert, who later died at Tanjung Pinang in 1873. He was elevated to National Hero of Indonesia status in 2004.