How to Configure extra buttons on mouse
If you just want the side buttons to do back/forward in ANY
  app/environment, this app is the most basic, streamlined one I've
  found for this purpose on Mac OS X, and completely free (donate!).
  http://sensible-side-buttons.archagon.net/


This answer was copied from here: https://superuser.com/a/1230059/51328