To install PHP, run:
$ sudo apt install php libapache2-mod-php php-mysql
After installing PHP, create info.php file in the Apache root document folder. Usually, the apache root document folder will be /var/www/html/ or /var/www/ in most Debian based Linux distributions. In Ubuntu 18.04 LTS, it is /var/www/html/.
Create test.php in the apache root folder as shown below.
$ sudo vi /var/www/html/info.php
Add the following lines:
<?php phpinfo(); ?>
Save and quit the file. Restart apache service to take effect the changes.
$ sudo systemctl restart apache2
Now, open up your web browser and type: http://IP-address/info.php in the address bar.
You will be pleased with a screen like below.
Install PHP modules
To improve the functionality of PHP, you can install some additional PHP modules.
To list the available PHP modules, run:
$ sudo apt-cache search php- | less
Sample output:
Use and arrows to move up and down between the result. To exit from the result, type q.
To find the details of any particular php module, for example php-gd, run:
$ sudo apt-cache show php-gd
To install a php module run:
$ sudo apt install php-gd
To install all modules (not necessary though), run:
$ sudo apt-get install php*
Do not forget to restart Apache service after installing any php module.