Miralax, about half the dose for adults once to twice daily. It dissolves in water and is totally tasteless so they'll take it without even knowing. Our daughter used to do the same thing - it was horrible, she was so cranky 'cause she neeed to poop but wouldn't! Miralax softens the stool, it's not a "laxative" so when he goes it will be softer and not painful. She eventually got over her fear of pooping but I still give it to her occasionally when I notice her stools are getting hard of when she eats lots of bananas and cheese :-). It's important to get it under control soon, otherwise it just becomes a terrible cycle. Even after you think you've got it licked, keep with the Miralax occasionally.
And encourage him to "let it out" when you know he needs to poop, and cheer and congratulate him when he does, then talk about how it "didn't hurt that time", to help him get over his fear of the pain. I had to coach our daughter how to "squat and push" instead of holding it in as her habit had become.
they also make "fiber gummies" but that always gave our daughter diarrhea so I stuck with the Miralax
Good luck!