How to use php version 8.2.4 or 8.1.7?

The fix would be installing a couple of libraries manually and this would be error prone and a waste of valuable time.

Reset your server to have a clean os with no webservers, databases, php.

Install latest cyberpanel on ubuntu 20.04 then use the recommended steps to install the php version of your choice. Please if you can avoid installing from source.

$ apt-cache search lsphp
# install all essentials for cyberpanel
$ apt-get install lsphp81 lsphp81-common lsphp81-mysql lsphp81-sqlite3 lsphp81-mbstring lsphp81-iconv lsphp81-mailparse lsphp81-imap lsphp81-intl lsphp81-zip lsphp81-gd lsphp81-curl lsphp81-xml lsphp81-bcmath

If not follow

then

$ cd /tmp
$ wget https://www.php.net/distributions/php-8.2.4.tar.gz
$ tar -xf php-8.2.4.tar.gz
$ cd php-8.2.4
## It is absolutely required to run ./configure with --with-litespeed since we have to build PHP with LSAPI
$ ./configure  '--prefix=/usr/local/lsws/lsphp82' '--with-libdir=lib64' '--with-zlib' '--with-gd' '--enable-shmop' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--with-curl' '--with-openssl' '--with-gettext' '--with-mcrypt' '--enable-mbstring=all' '--enable-mbregex' '--with-png-dir=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--enable-ftp' '--with-imap=/usr' '--with-imap-ssl' '--with-mysql=/usr' '--with-mysqli=/usr/bin/mysql_config' '--enable-pcntl' '--with-freetype-dir=/usr' '--with-pdo-mysql=/usr' '--with-litespeed'
$ make
$ make install

Then configure PHP 8.2 in WebAdmin console to be used as SAPI app

You need to restart lsws service for these changes to be effected.

service lsws reload