Measure and cut your lumber to form a ledger board matching the width of the pergola. The length of your ledger board should match the outer edge beam of the pergola. Level at desired height and mark the edges of the ledger onto the building.
Drill pilot holes at regular intervals. In the case of a wood-framed house and siding (or stucco), use a ledger board and lag bolts to secure it to the existing house. If you have a brick exterior, you'll need drill sleeve anchors to put into the brick or stone and secure the ledger board.
If hanging pergola rafters off of the ledger board with metal joist hangers, mark hanger holes onto ledge with a pencil and toe-nail or screw into place. If you don't want metal showing from underneath the pergola, use the notch method in Step 4.
Using a jigsaw, cut out a notch the width of each rafter along the topside of your ledger board. Make a notch for each rafter at your desired interval. Slot each rafter in the notch and secure by toe-nailing each rafter to the ledger board.
Once the pergola is attached to the house, make sure to secure each joint in the pergola well, both to maintain its structural integrity in inclement weather as well as to support the weight of any vines or plant material that you grow onto the pergola or any fixtures you hang.