How can i protect my site against hackers?

My friend’s site got hacked yesterday, he doesnt know how or why it got hacked, and i am wondering if i can protect my site against such hackers, and how do hackers seize control of your website?

any help would be appreciated