PHP 7.0 reached end of life on 03 Dec 2018 and is no longer being updated. It's strongly recommended to upgrade to the latest version as soon as possible. You can read the official PHP migration guide here.
Update the package list:
sudo apt update
Install the required packages:
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common
Add the Ondřej Surý PHP repository:
sudo add-apt-repository ppa:ondrej/php
Update the package list again:
sudo apt update
Install PHP 7.0 and common extensions:
sudo apt install -y php7.0 php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-json php7.0-mbstring php7.0-mysql php7.0-xml
Check the PHP version:
php -v
You should see output similar to:
PHP 7.0.33-0ubuntu0.16.04.16 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
Verify installed modules:
php -m
This will list all installed PHP modules.
Create a test PHP file:
echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/phpinfo.php
Access the phpinfo file through your web browser:
http://your_server_ip/phpinfo.php
This will display detailed information about your PHP installation.