Unlocking iphone 5 while on contract?

I have an I phone 5 which I bought of a friend. However, its locked on o2. Can I unlock it if it is still under his his contract?

Yes you can. I strongly suggest you get it unlocked by your current service provider as it won't re-lock, should you wish to update the ios anytime in the near future. Local shops can as well unlock the phone however there's no guarantee it won't re-lock if you update the iphone.

You MUST pay your contract before you unlock your phone. If you do your O2 may bar your phone