Replication between Postgres Versions and OS Versions

So I am relatively new to Postgres, our current environment got assigned to me and as luck would have it, we need to migrate soon. The OS goes out of support as well as the PostgreSQL Version that we currently have in use. I set up new Servers with the new Environment and was wondering if replication to the new environment would be possible?
We have to migrate from RHEL 7 to RHEL 9 as well as from PostgreSQL 12 to 15.
Replication would be the most comfortable for the availability of the applications. Now is this possible? Replicating the existing databases to the new environment, switching over and taking the old servers out of the cluster?