The simple answer is that this cannot be truly stopped.
A lot of the Middle East tension stems from the creation of Israel after the Second World War. Reversing that decision is not possible, or workable, and even then too much damage has been done.
The west are attacked for getting too involved in the Middle East (9/11) and attacked for doing too little (Manchester).
We cannot sort out the Middle East as we are in conflict with different countries for different reasons. Iran has been an ally to Iraq in driving IS out, but we have a conflict on nuclear weapons.
The Manchester bomber's father came to the UK as an asylum seeker from Libya. He then took his sons back to Libya to join a disorganised and unwieldy militia in the Arab spring against Ghadaffi (spelling). His sons were roughly 18, 16 and 14 ish. So two of them were children.
He was always going to come into contact with radicals as part of this, and handing a gun to a 14 year old is ludicrous!
The UK fought against Ghadaffi, so surely that should make the them support us, we have them asylum and then assisted in getting rid of their hated dictator... but then we left (given the fury over the Iraq war, trying not to stay too long) and Libya has descended into chaos.
The Middle East is a very complicated place and there is no easy answer as to how to prevent radicalisation.
We do what we can, support muslim communities (because true muslims are against the terror attacks), try to encourage integration.
Whatever foreign policy we adopt now will not stop those who believe we should have done more/less in their home country (depending on which country and which conflict you are talking about).