Yes, even if you've bought your phone second-hand. For Pay as you go, you'll need to have been using your PAYG SIM in the phone for 30 days. For Pay monthly you'll need to have paid three bills on time.
Unless you're using an Apple product, your phone must be in the UK for the unlock to work.