The instructions to compile sodium are the similar to imagic:
dnf install libsodium-devel
cd /usr/local/src/
wget https://pecl.php.net/get/libsodium-2.0.23.tgz
tar -xvzf libsodium-2.0.23.tgz
cd libsodium-2.0.23
/opt/alt/phpXX/usr/bin/phpize
./configure --with-php-config=/opt/alt/phpXX/usr/bin/php-config
make
make install
Make sure "extension=sodium.so" presents in appropriate .ini file.
P.S. if pecl.php.net is inaccessible for some reason, you can download php libsodium from Github:
wget -O libsodium-2.0.23,zip https://github.com/jedisct1/libsodium-php/archive/refs/heads/master.zip