so after more tinkering i think i’ve got it. 
-
i updated my nextcloud to 19.0. i was told on the overview page that i’m using an old version of PHP. indeed 17.2 was 4 years old. so i updated php to 7.4. i also updated mysql to 8.0 and apache to 2.4 and i already could see a vast improvement.
-
i tuned php. i set script memory limit to -1 (i disabled it) and i setup opcache memory consumption to 4GB. i found out that i had to edit the php.ini file in the apache2 folder of php, not the cli.
-
i tuned apache2 according to these guides:
https://www.liquidweb.com/kb/apache-performance-tuning-mpm-directives
https://www.tutsandtips.com/server/apache-localhost-loading-very-slow-here-is-the-solution -
i tuned mysql according to this guide here:
https://www.tecmint.com/mysql-mariadb-performance-tuning-and-optimization -
i disabled IPv6 on the server
-
i switched to the performance governor in cpufreq
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/power_management_guide/cpufreq_governors -
i also noticed that nextcloud is just much faster on chrome / chromium / vivaldi. i always use firefox to browser, but it seems that in this case there is a big difference in speed.
now the server is very fast. i’ll be checking it out for a few more days, but i think it should work.
funny that i solved my own problem, but at least other people who will have the same issue can just use this thread to figure it out.
AFTER A FEW DAYS
there is still a slight lag when i come back to nextcloud after a few hours for the first time, but it’s definitely much much better. and the next page loads are very fast. so i think all the settings above did help out.
just note that i am the only user on my server, and the server is dedicated to nextcloud. so depending on your situation, my solution might not work.
cheers guys! 