How To Install PHP for Apache on Ubuntu Server 20.04

Follow these steps to serve dynamic contents with PHP

Step 1 : Add PHP PPA Repository

Step 2 : Update the apt package repository and install PHP 7.4

Step 3 : Check if PHP is properly installed and which version has been installed:

Step 4 : Run command to install additional packages:

Step 5 : Create index.php under the html directory of our site:

Step 6 : Open example.com.conf from sites-available.

Step 7 : Add the following line under the VirtualHost directive

Step 8 : Save the changes and reload Apache

Step 9 : Now, access your site with your browser, and you should see a page with information regarding the installed PHP