You must apply for asylum if you want to stay in the UK as a refugee. To be eligible you must have left your country and be unable to go back because you fear persecution.
You should apply when you arrive in the UK or as soon as you think it would be unsafe for you to return to your own country. Your application is more likely to be denied if you wait.
Asylum is protection given by the United Kingdom to someone who is fleeing persecution in their own country. It is given under the 1951 United Nations Convention Relating to the Status of Refugees.
The UK also adheres to the European Convention on Human Rights, which prevents the UK from sending someone to a country where there is a real risk that they will be exposed to torture, or inhuman or degrading treatment or punishment.