It is not known when Gu Yanlang was born. According to his biography in the New Book of Tang, he was from Feng Prefecture. Both he and his younger brotherGu Yanhui served as junior officers at Tiande. The defender of Tiande, Cai Jing, considered both of them to have appearances that indicated that they would be later successful, and therefore had his son give them money. During the subsequent major agrarian rebellion led by Huang Chao, Gu Yanlang and Gu Yanhui served in the campaign against Huang and participated in Tang's recapture of the capital Chang'an from Huang. Gu Yanlang was subsequently made a general of the imperial guards.
As military governor
In 887, then-reigning Emperor Xizong made Gu Yanlang the military governor of Dongchuan Circuit. When he reached Jianmen on the way to his post, the subordinates of Chen Jingxuan the military governor of neighboring Xichuan Circuit seized the staff that Emperor Xizong bestowed on him and refused him entry toward Dongchuan, and he was forced to stay at Li Prefecture for some time. Only after further negotiations by imperial emissaries did Chen allow Gu to report to Dongchuan. Once he got there, he made his brother Gu Yanhui the prefect of Han Prefecture. Meanwhile, a former colleague of Gu Yanlang's in the imperial guards corps, Wang Jian, had seized Lang Prefecture and claimed the title of prefect, and was sending the troops under him to raid the nearby regions. Gu feared Wang's potential raids, and therefore frequently sent emissaries to Wang to affirm their friendship and to give Wang gifts; as a result, Wang did not raid Dongchuan. Chen became apprehensive that Gu and Wang might join their forces and attack Xichuan. Chen's brother, the former paramount eunuchTian Lingzi, who had previously adopted Wang as a son, suggested that he would be able to summon Wang to serve under Chen. Chen agreed, and Tian subsequently wrote a letter inviting Wang to serve under Chen. Wang, receiving Tian's summons, initially indicated that he agreed, and he left his family at Dongchuan's capital Zi Prefecture with Gu, while he himself headed toward Xichuan's capital Chengdu. However, while Wang was on his way, Chen's subordinate Li Ai persuaded Chen that Wang could not be trusted, and Chen tried to stop Wang. Wang, however, would not stop, and he defeated officers Chen sent to stop him and proceeded to Chengdu. Gu then launched an army under Gu Yanhui's command to aid Wang. They put Chengdu under siege, but could not capture it, so they lifted the siege. Wang, however, continued the campaign against Chen, and he raided and seized a number of prefectures of Xichuan Circuit. After Emperor Xizong died in 888 and was succeeded by his brother Emperor Zhaozong—who had despised Tian—Wang submitted a petition to Emperor Zhaozong that argued that Chen and Tian were renegades against imperial rule and that the imperial government should launch a campaign against them, and Gu joined Wang's petition as well. Emperor Zhaozong thereafter commissioned the chancellorWei Zhaodu as the new military governor of Xichuan and summoned Chen back to Chang'an to serve as a general of the imperial guards. When Chen refused, Emperor Zhaozong declared a general campaign against Chen, with Wei in command and Gu, Wang, and Yang Shouliang the military governor of Shannan West Circuit serving as Wei's deputies. The campaign lasted for years. By 891, Chen was in a desperate state, but the imperial government's resources had become drained due to a recent defeat in a campaign against another warlord, Li Keyong the military governor of Hedong Circuit. Emperor Zhaozong decided to end the campaign against Chen; he issued an edict restoring Chen's offices and ordering Gu and Wang to withdraw their troops. Wang, however, saw that Chen was near defeat, and he intimidated Wei into returning to Chang'an and leaving him in command of the operations. Chen and Tian surrendered, and Wang became the military governor of Xichuan. Soon thereafter, Gu died, and Gu Yanhui took over as the acting military governor of Dongchuan. His son Gu Zaixun would later become a close associate of Wang Jian's son Wang Zongyan—the second emperor of Former Shu, which Wang Jian founded—and serve as Prefect of Jia Prefecture.