Upgrading PHP and Moodle is certainly a good first step. 5.4 is no longer supported, and Moodle 3.1 which is the last version to support PHP 5.4 is in security-only support. Upgrading PHP is somewhat beyond the scope of a Moodle development forum, so you'll probably be best served searching for instructions specific to your server platform.
PHP 7 has been supported by Moodle since Moodle 3.0, so if you are on 3.1 you should be able to upgrade PHP, then upgrade to the latest version of Moodle. However, if you are on an older version of Moodle you should upgrade to 3.1 first, then upgrade PHP, then upgrade to the latest version of Moodle. Refer to the Upgrade notes for the version you are upgrading to. Back everything up before you start!