In this tutorial we are going to learn how to install PHP 7 on Ubuntu 18.04 Bionic Beaver. We will also install and configure its prerequisites. The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic and interactive Web pages. As of 2018, PHP was used as the server-side programming language on 85% of 10 million most popular websites
I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install PHP 7 on Ubuntu 18.04 Bionic Beaver
Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:
apt-get update -y apt-get upgrade -y
Step 2. Installing PHP 7 on Ubuntu 18.04 Bionic Beaver.
First, use the following set of commands to enable PPA for PHP 7.2 in your Ubuntu system:
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install -y php7.2
Once the package has finished installing, we can test PHP in the command line:
If PHP installed correctly, you should see something similar below:
PHP 7.2.3-1ubuntu1 (cli) (built: Jul 16 2018 23:06:57) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.3-1ubuntu1, Copyright (c) 1999-2018, by Zend Technologies
You may also need to install modules based on your application requirements. Use the following command to search available PHP 7 modules in the package repository:
sudo apt-cache search php7*
Step 3. Verify PHP for Apache.
Create a new file called info.php in /var/www/html.
sudo nano /var/www/html/info.php
Paste in the following PHP code:
Then, load this file in the browser by going to:
http://example.com/info.php or http://your_ip/info.php
Congratulation’s! You have successfully install and configured PHP on your Ubuntu 18.04 LTS server. Thanks for using this tutorial for installing PHP 7 on Ubuntu 18.04 LTS (Bionic Beaver) system.