In addition to the docs that Richard provided:
- You might have more luck if you move from last stable release to last stable release. In other words, I wouldn't attempt to upgrade from 4.2.f directly to 5.1.g, for example. Instead, I'd upgrade from 4.2.f to 5.0.d to 5.1.g.
- Always make sure that you are running supported dependencies at each step, see
https://www.alfresco.com/services/subscription/supported-platforms. For example, pay attention to Java, MySQL/PostgreSQL, and OS versions required for 4.2.f, 5.0.d, and 5.1.g.
- Backup before each upgrade. It is common to have to back out, so make sure you have a good backup.