Hello it depends on your distro eg Ubuntu(Apache2) , Windows etc most code written for php 7.4 should work with 8.1. Ive installed both and have the option to switch manually or you can setup domains to use both but its not straight forward. also if you do upgrade certain modifications will need to be done. If your using Ioncube the ioncube loaders will need to be added for 8.1
Otherwise anything using ioncube on php 8.1 wont be visible. I'm personally running Apache2 on Ubuntu 20.4 i have 7.4 and 8.1 installed with ioncube loaders for 7.4 everything works fine on 7.4.
Heres some information relating to upgrading to php 8.1 on Apache2 on Ubuntu
Enter the following commands on the terminal to upgrade PHP:
1 . To install the latest
PHP 8.1, you need to install PHP 8 binary packages that are available in the Ondrej Sury PPA repository.
root@gateway:~# add-apt-repository ppa
ndrej/php
Press ENTER to add the repository.
2. Install PHP 8.1
root@gateway:~# apt-get update
root@gateway:~# apt-get install php8.1
3. Now install
PHP 8.1 with all necessary modules with the command below.
root@gateway:~# apt install php8.1-cli php8.1-xml php8.1-gd php8.1-curl php8.1-mysql php8.1-ldap php8.1-zip
4. Restart Apache2
root@gateway:~# systemctl restart apache2
5. Disable the current version PHP modules whichever you are running and enable the modules for 8.1 version
root@gateway:~# a2dismod php* ( eg: a2dismod php7.4 )
root@gateway:~# a2enmod php8.1
6. Restart the Apache2 service.
root@gateway:~# systemctl restart apache2
After following the above guide you will be running php 8.1 to verify this
go to your terminal root@your username then type in "php -v"
you should see a screen similar to this
PHP 8.1.6 (cli) (built: May 24 2022 21:16:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies
Hope ths helps Cheers