Fixing WordPress permalink issues and 404 errors

How to fix WordPress pages and posts returning 404 errors when the homepage loads fine, covering permalink settings, .htaccess regeneration, server configuration and WooCommerce product 404s.