How To Install PHP on Linux Ubuntu
PHP is used for server-side applications such as the WordPress CMS, PHPMyAdmin, Nextcloud and other systems.
This article explains the necessary steps for installing PHP on Ubuntu 20.04 and integrating it with Apache.
Linux Ubuntu version 20.04 includes PHP version 7.4 by default. However it can be useful to know how to reinstall this version or how to install other versions or PHP on other Ubuntu versions.
First, do an apt update as per usual prior to installing new packages:
apt install php libapache2-mod-php
Numerous php extension modules are available. For example, for MySQL.
To install the php MySQL extension:
apt install php-mysql
then restart Apache so PHP will be loaded:
systemctl restart apache2
check that it is running:
systemctl status apache2
You can test php as follows:
Create a file named /var/www/html/info.php with the following code content:
Point your web-browser at http://22.214.171.124/info.php.
You should see the php config information page displayed for the server
You can confirm the current installed php version with:
root@gemini:/var/www/html# php -v
PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( 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