The most popular way is using hook and loop Velcro or one of it’s non-trademarked derivatives. Simply attach the loop side to your pedalboard and the hook side to your pedals themselves and stick them on your board. Some pedalboards will come with the loop side already attached, so you can quickly add and remove pedals. Hook and loop is surprisingly strong, so provided you attach them firmly, there’s little chance of your pedals moving around.
You can also attach pedals with cable/zip ties. This method is more popular if you have a pedalboard that doesn’t have traditional rails, like some of the more modern, lightweight pedalboards. However some guitarists feel it looks a little ugly, and attaching them in this fashion can make it awkward to remove the pedal, especially if you need to quickly swap something on your board.
They’re pretty rare, but you can also get pedalboards with their own bespoke fittings, like those from Temple Audio. For the most part you’ll be deciding whether to use zip/cable ties or hook and loop fastening.