Attach the border trim first, measuring and cutting carefully for a tight fit where the pieces meet. Apply construction adhesive to the backs of these pieces, and attach them by driving finish nails at least 2-1/2 inches long into studs. Since you'll be painting the rails, stiles, and walls later, you might be tempted to fill bad joints with caulk, but avoid relying on such fillers: Those caulked areas will show up even after you apply paint, and will only become more visible over time.
To ensure tight joints, it's a good idea to initially cut each piece a fraction of an inch long so you can check its length on the wall and "sneak up" on the final cut with a series of fine cuts. Even then, leave the piece just a hair long after the final cut; this allows you to flex the piece outward to fit it into position, forcibly press it flat against the wall, and force its ends tight against adjoining pieces. Measure and mark odd angles (other than 90 degrees) using an adjustable bevel to transfer the angle from the wall to the piece you're about to cut. If you have to drive a nail closer than an inch from an end or edge, predrill a hole for the nail to avoid splitting the wood or MDF.
Next, attach a center stile. It might not fall on a stud, so attach it with construction adhesive only, using painter's tape to temporarily hold the stile in position. After the construction adhesive cures, add the center rail on both sides of it. Attach the remaining rails and stiles, working out from the center.