Many people have recommended that I buy a lock for his bedroom door. They say my child will quickly get the message. First you need to consider whether your son is actually ready for bed at bedtime. Maybe he just isn't tired. Try a little later.
Children respond best to a routine.
A typical ritual involves a snack, bath and teeth brushing, story time, then to bed. Let him have some control by allowing him to leave his bedside light on and look at books until he's ready to fall asleep. It is very common for children who sleep alone to get up during the night. If he has a sibling, consider having them share a room, then when he wakens at night, he's not alone. He may be having nightmares or just waking and feeling very alone in the dark.