Thanks, that worked. I just changed two things.
1. Extracting tar files in /tmp.
2. My lsphp module code was different, found using filezilla. (20210902)
3. Used php81 instead 82.
So this was my whole code that worked:. Thanks again!
cd /tmp
wget
https://download.imagemagick.org/ImageMagick/download/ImageMagick.tar.gz
tar -zxvf ImageMagick.tar.gz
cd /tmp/ImageMagick-7.1.1-27/
./configure
make
make install
ldconfig /usr/local/lib
cd /tmp
wget
https://pecl.php.net/get/imagick-3.7.0.tgz
tar -zxvf imagick-3.7.0.tgz
cd /tmp/imagick-3.7.0
sudo /usr/local/lsws/lsphp81/bin/phpize
./configure --with-imagick=/usr/local/lsws/lsphp81 --with-php-config=/usr/local/lsws/lsphp81/bin/php-config
make
make install
echo "extension=imagick.so" >> /usr/local/lsws/lsphp81/etc/php/8.1/mods-available/40-imagick.ini
cp modules/imagick.so /usr/local/lsws/lsphp81/lib/php/20210902/
service lsws restart
killall lsphp