Updating the PHP version is really easy if you have the server root access or sudo access. Here I will explain how we can update the PHP version using command line.

Add the Personal Package Archive (PPA)

before start updating the PHP version one should add PPA to system. For the run the below command. Make sure you are logged in as root or you've sudo user access.

sudo add-apt-repository ppa:ondrej/php

then update the repository

sudo apt-get update

Next we need to install the new version PHP and the supported components.

If you want install PHP 7.4 run the following command

sudo apt install -y php7.4-mysql php7.4-dom php7.4-simplexml php7.4-ssh2 php7.4-xml php7.4-xmlreader php7.4-curl php7.4-exif php7.4-ftp php7.4-gd php7.4-iconv php7.4-imagick php7.4-json php7.4-mbstring php7.4-posix php7.4-sockets php7.4-tokenizer

similary to install PHP 7.3 replace all the occurances of php7.4 to php7.3 in the above command.

You can also install the addtional plugins for Wordpress if required.

sudo apt install -y php7.4-mysqli php7.4-pdo php7.4-sqlite3 php7.4-ctype php7.4-fileinfo php7.4-zip php7.4-exif

Next step is to install the Apache with prefork MPM

sudo apt install libapache2-mod-php7.4
and
sudo a2enmod php7.4

Once installed u can remove the older versions of PHP

sudo apt purge php7.0 libapache2-mod-php7.0 # remove php7.0
sudo apt purge php7.3 libapache2-mod-php7.0 # remove php7.3

Your are done.

Now let's verify the installed version running the below command from CLI

php -v