A very small percentage of people can actually overhead press with a barbell without pain.
Why? It requires you to press overhead while maintaining a braced core (ribs down position) to protect the spine. And since most people don't have the ability to do so, hyperextension in the lower back occurs with shear force created on the spine. Not good.
To press overhead without pain, you need adequate shoulder and thoracic mobility while maintaining core/glute engagement throughout your set. Until you get that sorted out, here are two great alternatives:
1. Banded Single-Arm Overhead Landmine Press
Any bilateral (two-sided) press variation places greater demand on the body to get into a safe, optimal overhead position without adding shear force on the spine. Pressing directly overhead (as with the strict straight bar variation) requires a combo of shoulder and thoracic mobility.
Since most people lack these prerequisites, this single-arm landmine variation is a great alternative. Leaning forward into the press with your torso and arm angle at a similar diagonal line reduces the range of motion your shoulders have to go through in an overhead position. It also minimizes hyperextension in the lower back, taking stress out of the spine.
You can do this variation with or without a resistance band. The band simply has more resistance during the lockout of the press.
2. Overhead Trap Bar Pin Press
It's easier (from a mobility perspective) to do overhead lifts in a staggered or half-kneeling stance as opposed to a bilateral standing position. What's more, a neutral grip (palms in) overhead position is safer on the shoulders as opposed to a pronated (palms forward) grip as seen in the strict barbell press.
The overhead trap bar press looks funky, but it's pretty damn awesome. It'll feel less shitty on the shoulders in comparison to strict overhead bar presses.