The gastalds (or counts) of Capua were originally vassals of the Dukes of Benevento. In the early 840s, Gastald Landulf I declared independence from Benevento after Salerno had done the same. That caused a civil war in Benevento, which lasted for more than 10 years. At the end of it, Capua was made a vassal of Salerno by the Holy Roman Emperor Louis II. However, this did not last, and by the end of the 9th century Capua was effectively independent.