Installing PHP

PHP is the component  that will process code to display dynamic content to the website visitors. In addition to the php package, you’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. You’ll also need libapache2-mod-php to enable Apache to handle PHP files. Core PHP packages will automatically be installed as dependencies.

$ sudo apt install php libapache2-mod-php php-mysql

Once the installation is finished, run the following command to confirm your PHP version:

$ php -v


The response should be similar to this:

PHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies


At this point, your LAMP stack is fully operational.
the default root directory of the Apache server points to /var/www/html. The index.php file in this directory contains the Apache2 UBUNTU default page.


Testing the PHP processing

Create a PHP test script to confirm that Apache is able to handle and process requests for PHP files.

$ nano /var/www/info.php

Nano is an DOS-style Linux editor. use arrow-keys to position the cursor where to enter or delete text. For more on the use of nano, look here.

/var/www/your_domain/info.php
<?php
phpinfo();

Enter the text as displayed and save by pressing keys cntrl+x then y then enter

Test the script with a browser using the same address testing Apache.

$ http://<server-ip-addr>/info.php

The result should display PHP overview file

phpinfo


PHP installation successfully completed

Lamp installation completed