Forty or fifty years ago, the Middle East was much more secular and westernized. What happened?
For start, many Middle Eastern nations were more secular and westernized, but it isn't like those views were found universally amongst the residents of those nations. There were definitely conservatives, they just generally weren't in any positions of power and often weren't even in the main cities. Terrorist groups as we see them existed during the Cold War era as well, though their goals and methods were often quite different than their descendants in the Middle East today.
That being said, the main thing that one should remember is that pretty much all of these "secular and westernized" governments were dictatorships or autocracies of some form or another. People like Gamal Abdel Nasser, Hafez al-Assad, and Mohammad Reza Shah Pahlavi weren't exactly accepting of things such as dissent, peaceful or otherwise, and they had a strong habit of jailing opposition leaders, censoring the press, and presiding over regimes that were often very corrupt. Egypt is quite notorious for essentially remaining under martial law almost continuously from 1967 to today (there was a brief reprieve in 1980).
Westerners look at old photos of Alexandria and Tehran and like to reminisce of a time when people were wandering about those places in miniskirts and whatnot, but the Cold War was not exactly completely rosy in the Middle East. Now, this is a generalization, of course - after all, I'm pretty much completely leaving out the Arabian Peninsula itself (after all, the people in charge there were mostly quite conservative) - but across the Middle East there were genuine political and economic grievances (economic trends are hugely important - things like price fluctuations can have a big impact on public attitude), and given the overbearing nature of many of the governments of the Middle East, the people often had few ways of airing those grievances. Want to have a peaceful street demonstration? Want to be able to vote for an opposition party in a fair and safe election? Want to be able to print and distribute your own newspapers? Too bad (once again: this is a generalization, to fit the nature of the question), you probably can't. There is also the factor that in some Middle Eastern nations, minority groups had essentially ended up dominating government and locking out others - the two main examples being the Sunnis in Iraq and the Alawis in Syria. Most other Middle Eastern nations weren't like this, but in general the borders of the Middle East were often drawn without any real consideration as to what sorts of people would be living within those nations.
When a government shut downs more legitimate and moderate means of dissent, it forces those sentiments underground. Sometimes this resulted in the opposite of what people typically associate with radical Middle Easter groups - it took the form of highly secular Marxist-Leninist opposition groups. Communists played a large role in the Iranian Revolution of 1979. Leftist movements have also been very important in Palestine, forming a large part of the PLO. Very often, however (especially after the fall of the USSR), this sort of underground organization was conducted by conservative Islamic groups. The Muslim Brotherhood is perhaps the best known example of this - they've been around in Egypt since 1928 and for much of their history they have faced government repression. A lot of Islamic terrorist groups (as well as Communist ones) rose in this era (though some predated it) to attack the governments of the Middle East themselves - al-Queda's insistence on attacking the West set that organization apart from the rest when they rose to prominence.
Basically, when people are angry at their lot in life - whether it be due to economic malaise, price fluctuations of basic goods, political repression, what have you - and they don't have legitimate means of affecting change in the policies of their states, they will often come to support more radical organizations. The Middle East is far from the only part of the world where this has occurred. In Iran in 1979, the fall of the Shah meant that there was a power vacuum, one that ended up being filled by the Islamists who would create the theocratic Iran that exists today. They certainly hadn't been the only opposition group when the Shah was in charge, but they proved to be the most organized and capable in the aftermath of the Revolution. To talk about a lot of other nations would infringe upon the 20-year rule, but I hope that I have sort of established some sort of point or another, albeit a generalized one.
You need to go further back than that; the rise of modern militancy can be directly traced to the destabilising efforts of the German intelligence service during WWI.
AJ Barker's The First Iraq War 1914-1918 (originally titled The Bastard War) is an excellent source, if a little light on the politics. EDIT: For that side of it see When God Made Hell by Charles Townshend.