Jerry has it pretty much nailed. Having done some of these, and have another one in progress right now, you will need to create a temporary server environment, either physical or virtual, and deal with that first upgrade step from Version 4.X to Version 5. Getting through that database transition to InnoDB is key, and depending on the size of your V4 database, it may take hours or even days, depending on the hardware resources available.
One thing that will help, is leaving your old log table behind in your V4, just re-create the empty table structure after you dump and migrate your database into your upgrade environment. It likely has millions or potentially tens of millions of rows in it, and the version upgrade will burn significant time on the storage engine conversion for that table alone.
Chances are, trying to do OS/platform upgrades and OpenEMR version upgrades all on that platform at the same time will prove to be rather frustrating. If you have control of physical hardware, you’d be better off building a clean Ubuntu 26 LTS server platform, and establish a temporary VM on top of it running an Ubuntu 16 or 18 environment to get you from Version 4.X to Version 5.x, then move everything to the physical host and completely the rest of the sequence from V5 to V8.2.
As Jerry mentioned, if you had any customizations to your V4 environment, it’s going to be critical to have a running copy of your V4 to compare with if you wish to re-create any for them, because none of the old application code from V4 is going to function anymore in the V8.x infrastructure.
You didn’t mention the underlying LAMP stack, but if your V4 platform was running MySQL, this is also a great time to migrate your database back end to MariaDB.
It’s extremely important to pay close attention to the output during the version upgrade processes, you may even want to print/save the output for troubleshooting if & when you run into problems or data anomalies.
Running a full database check via the built in tools in MariaDB is also highly recommended, because if you have any table level data issues, those can and will trip up the version upgrade process. Newer versions of MySQL/MariaDB, have changed standards and handling for things like date fields, and there may be data rows in your V4 database that need to be manually addressed and corrected before the version upgrade manipulations will execute correctly.
One last thing to point out, if your old server was vintage 2018, you’ll probably benefit from having newer/faster hardware to grind through all the version upgrade operations, and as Jerry already made clear, you really need to maintain your V4 environment for data rentention, reference and QA both during & after your version upgrade.