Follow procedure at https://www.linuxcapable.com/how-to-install-php-8-1-on-rocky-linux-9/
dnf config-manager --set-enabled crb dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm dnf install https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm dnf remove php php-fpm dnf remove php* dnf module list reset php dnf module list php dnf module enable php:remi-8.1 dnf install php php-mbstring php-mysqlnd php-pecl-mcrypt php-pecl-mysql
Now check for installed version of PHP:
php -v
For issues running PHP, check Rocky Linux PHP 8.1 Upgrade for workarounds.