PHP Installing on Linux/Unix Environments Command Line Install Using APT for PHP 7


This will only install PHP. If you wish to serve a PHP file to the web you will also need to install a web-server such as Apache, Nginx, or use PHP's built in web-server (php version 5.4+).

If you are in a Ubuntu version below 16.04 and want to use PHP 7 anyway, you can add Ondrej's PPA repository by doing: sudo add-apt-repository ppa:ondrej/php

Make sure that all of your repositories are up to date:

sudo apt-get update

After updating your system's repositories, install PHP:

sudo apt-get install php7.0

Let's test the installation by checking the PHP version:

php --version

This should output something like this.

Note: Your output will be slightly different.

PHP 7.0.8-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

You now have the capability to run PHP from the command line.