How to Install PHP 7.4 on Ubuntu Server 20.04

We will learn how to install PHP and set it to work alongside the Apache web server.

Step 1 : PHP 7.4 is included in the default Ubuntu repository for 20.04. You can list each of the available PHP 7.4 packages with the following command:

apt-cache pkgnames | grep php7.4

Step 2 : Next, Install PHP 7.4 from the Ubuntu package repository:

sudo apt-get install php7.4 -y
    sudo apt-get install php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip} -y

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

Step 4 : Create index.php under the public_html directory of our site:

cd /var/www/example.com/public_html
    nano index.php

Step 5 : Add the following contents to index.php

<?php echo phpinfo(); ?>

Step 6 : Save and exit the index.php file.

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

sudo nano /etc/apache2/sites-available/example.com.conf

Step 8 : Add the following line under the VirtualHost directive:

DirectoryIndex index.php index.html

Step 9 : Save the changes and reload Apache:

sudo service apache2 reload

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

Add Comment