It's common to say that the background for the war started with the establishment of al-Queda training camps in Afghanistan. This is a terrorist group, and it's in an alliance with the Taliban. The Taliban controlled Afghanistan from 1996 to 2001, when NATO and the Northern Alliance established a new democratic government, and took most of Afghanistan from the Taliban. In 2001, after the 9/11 terrorist attack in the United States, the President declared a war on the terrorist groups in Afghanistan.
Personally, I believe the conflict started earlier. The real conflict started in 1979, when the United States and Western-Europe started gaining more influence in the Middle-East. Egypt and Israel ended their war with help from the US and Saudi-Arabia, Iraq and Yemen became more friendly with the West. In Afghanistan the Marxist party gained more support and the government was very unstable, this resulted in a military coup. After the coup d'etat, the prime minister unsuccessfully attempted several reforms. Then there was another coup, where the PDPA (Afghan Communist party) overthrew the recently formed government.
When this latest coup d'etat met resistance, the Soviet Union supported the PDPA, and deployed troops to support them. This became a full-scale invasion, to which the United States reacted. They supported the resistance in Afghanistan, constructing the terrorist groups that they have problems with today.
Possibly to be continued.