One should move as soon as they are able, as per Qur'an 4:97-99 and the example of the Prophet (S) and the early Muslims (who made the first migration to Ethiopia and the second migration to Medina).
Sincere believers along history till now face challenges opposing them to practice their faith, but they always stay strong and never give up their religious duties. The patience (Sabr) from faith is like the head from the body as the Hadeeth says.
Patience and wisdom is the way to tackle the challenges with strong faith that Allah (SWT) never leaves His servants.
Insofar as it is possible, it is good to try to adjust your environment to avoid triggers (for instance, avoiding online or television material with indecent content, looking away from certain advertisements or behaviour outside). I know that this can be difficult in some places which have become quite explicit! It is related from the Prophet (S) - and I am sure you have heard this - that if you lower your gaze, you will see wonders.
As for thoughts, to some degree we have control over our thoughts, you can try to change what you are thinking about and focus on something else if you find your thoughts wandering.
If you are a male and really struggling with this, fasting has been recommended too and may be helpful (as long as you do not do it to excess).
Anyway this is part of being a normal human being, all you can do is your best and be compassionate with yourself while trying to navigate the straight path.