Your post is missing essential information:
- which operating system
- which web server
- if Apache2, which php SAPI
- from Owncloud version
- to Nextcloud version
Broadly speaking, this are the steps:
- install the required php (7.2)
- connect the web server to the new php
- continue migration and update.
The new (old 7.2) php can then simply be removed again after Nextcloud has been updated to new versions that no longer require that version.
If you are on an Ubuntu or Debian system, you can use → the php-updater script ← to install new (or old) versions.
Much and good luck,
ernolf