Place heel of the leg being stretched onto a box or bench that is approximately knee height (this stretch can also be performed with the heel on the floor).
Make sure hips are kept square (ie facing forwards not twisted to the side).
Keep the stretched leg as straight as possible and lean forwards from the hip with buttocks out and back straight.
Do not hunch your back or slouch forward.
Get to the point of a mild stretch and hold.
Repeat for each leg.
Notes
There are several different stretching exercises for the hamstrings, see also hamstring stretch supine and sitting.