Add the trusted Ondřej PHP PPA repository to manage multiple PHP versions and receive the latest updates seamlessly. Use the following command:
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
This is compatible with Ubuntu 18.x to 24.x, ensuring access to the latest PHP features and security updates.