Maybe you can't. Most people can.
Here's an explanation from a health forum:
There does seem to be one of those "urban myths" that men cannot pee with a full erection. Of course, most can, but relatively slowly and with the major restriction that it points upward and is just - impractical.
There are two deliberate "actions" associated with peeing (or not). One is to relax the sphincter or "stopping" muscle, and strain (the abdomen) to eject the urine. The opposite is to contract the sphincter and bulbocavernosus (BC) muscle in order to shut off the flow.
What is interesting is that the latter action, contracting the BC muscle at the root of the penis, is the very action that is used to forcibly ejaculate the semen when it happens involuntarily, or automatically. And indeed, it automatically contracts in response to strong stimulus to the glans (penis head), and particularly during an erection.
You will (should) have noticed this when you, for whatever reason, suddenly contract the BC to "shut off" peeing in the middle. While it stops, a forcible spurt is produced in the process - almost as forcible as semen ejaculation.
And in this respect, it is not surprising that the stronger an erection and the more forcibly (distance) semen is ejaculated, the more difficult it is to pee with the same erection. However, since it is always possible to ejaculate, by the same token, it is always possible to pee with an erection even though it is slow and again, you will note that deliberately "stopping" the pee intermittently actually shoots it much faster for just that moment.