I am going to receive a loan from my friend so that I can pay off my mortgage and some other debts. I want to officially record the loan so that my friend is legally protected and guaranteed to be repaid from the equity of the house. How do I record this kind of thing?
You're replacing one loan secured by your house (aka "mortgage") with a different loan secured by your house (aka "mortgage").
You and your friend must write out an official loan contract (amount, interest rate, years, monthly payment, ability to pay early, fees -- if any -- for early payment, and description of the property). Both must sign it in front of witnesses and then file it with the county where your property is located.
Whatever you do... no matter your financial circumstances, pay that note on time every month!!!