I generally upgrade my servers with the following command:
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
Is there a clean way to upgrade everything except for PHP, or would it be easier just to upgrade everything and then rollback to PHP 8.2? I learned the hard way with a recent upgrade that WordPress isn't ready for PHP 8.3 (https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/), and had to do a complete fresh install of PHP:
sudo add-apt-repository --remove ppa:ondrej/php
sudo apt purge php*
sudo apt autoremove
sudo rm -rf /etc/php/8.3
sudo rm -rf /usr/lib/php
sudo apt install php php-mysql
sudo service apache2 restart
Note: Ubuntu moved to PHP 8.3 on January 18th: https://discourse.ubuntu.com/t/noble-numbat-release-schedule/35649