Measure the width of the opening on the porch where you wish to install a gate. Subtract 2 inches from that measurement. Cut two lengths of 2-by-2-inch lumber according to the measurement. The 2 inches that were subtracted will add room for the hardware on the gate.
Measure the height of the porch railing. Subtract 2 inches from the measurement to allow for swinging room underneath. Cut two 2-by-2-inch boards according to the height measurement.
Position the four previously cut pieces of wood to form a rectangle. The width pieces are the top and bottom, and the height pieces are the sides. The top and bottom pieces will come over the ends of the side pieces. Apply wood glue to the meeting surfaces, then screw the rectangle together with one 2 1/2-inch wood screw at each corner.
Measure the distance from the top-right corner of the rectangle to the bottom-left corner. Cut a piece of 2-by-2-inch lumber to fit snugly inside. This is the cross brace and will keep the gate from sagging. Glue the cross brace, then attach it with one 2 1/2-inch wood screw at each end.
Cut several lengths of 1-by-2-inch lumber to measure the same as the side pieces of the gate. These are the gate pickets. Place the first gate picket across the gate frame parallel to the sides. The ends of the picket should be on the top and bottom of the gate frame. Secure it in place by screwing a 2-inch screw into the top, bottom, and cross piece. Repeat to install pickets all the way across the gate, leaving a 2-inch space between each one.
Thoroughly sand the gate with 120-grit sandpaper to remove any rough spots. Apply an even coat of wood paint or stain so the gate matches the porch railing. Let the paint or stain dry thoroughly for several hours.
Screw one side of a gate hinge to the top of one side of the gate using 2-inch wood screws. Attach a second hinge to the bottom of that side. Attach one half of a gate latch to the top of the other side, using 2-inch wood screws.
Ask an assistant to hold the gate in the porch opening. Adjust the gate so its top is even with the top of the railing. Attach the other end of the hinges to the gate railing, using 2-inch wood screws. Install the other half of the gate latch to the railing on the opposite side, also using 2-inch wood screws. Ensure the gate has room to swing, and adjust as needed.