Correct way to migrate OC from ubuntu 14.04 to 16.04

I have OC 8.2.8 installed via repository
deb /
on ubuntu 14.05.5 (LTS)

I have installed my new home server with ubuntu 16.04 and I want to migrate OC to this machine and to upgrade it to 9..1

I would like to understand which is the better procedure to achieve the aim.

Is it possible to upgrade via apt on ubuntu 14.04 from 8.2 to 9.1 and then move db and files to a fresh 9.1 install on the new ubuntu 16.04 or is better the opposite?

I would like to use new php7 on the new machine.

I'll appreciate if someone could point me to some tested ways to perform this double upgrade.

Thank you

I am not a specialist... But what I would do is:
* install a fresh OC 9.x on the new machine
* copy the data directory from the old machine to the new one
* use phpmyadmin to save the base from the old machine and to upload it on the new machine.
* set up the right parameters in config
Doing so, you don't change anything to the working OC, therefore you can come back on a working install whatever happens.
Beware of the user and password in Mysql and of the permission for the directory you copy.

Than you foe your answer. That is what I would have done if the versions of OC were the same. But in the old pc I have OC 8.2 are the DB and data directory the same on the two versions?

You might be right. It would be more secure to install the same version you already have on the new machine, make the migration of the db and of the data, and then upgrade the version on the new machine. Once again, this is a way to avoid modifying anything on the running machine.
Once the new one is running well, you can change your DNS zone file to have your url pointing on the new machine. And shut down the old one.