Terminal app
To be able to install PHP you need to use the Terminal.
If you want to use Ubuntu to its full potential as a web development environment then you will need to know how to work with the Linux terminal.
To open click the Show Apps icon in the dock, then search for ”terminal” to show and open the app.
How to install PHP
There are two ways to install PHP, you can either install PHP 8.3 or install the latest one (8.4) or an earlier version.
Install PHP 8.3
Ubuntu comes with an install setup for PHP 8.3, you can copy and paste the below command and then press the Enter button.
Press the Y key when prompted to go ahead with the installation.
sudo apt install php
Install PHP - Any version
Add a new install source for PHP by using the following command.
sudo add-apt-repository ppa:ondrej/php
Now update the Advanced Package Tool (APT) to update and add the new install source for PHP
sudo apt update
You can now install whichever version of PHP you need with the following install command.
sudo apt install php8.4