UPDATED ON OCT 2016!


PHP is our last component of the stack. This scripting language will process code, handle requests, establish database connections and run scripts.

Installation

Ubuntu 16.04 has switched to PHP 7.0 with a new infrastructure for PHP package. You can’t install php5 on Ubuntu 16.04, but you can install PHP 7.0 packages with:

ronin@Komei:/$ sudo apt-get install libapache2-mod-php php7.0 php7.0-mcrypt

Now, create a quick script to test the configuration of PHP. We will use the command line editor vim.

ronin@Komei:/$ sudo vim /var/www/html/info.php

Or

ronin@Komei:/$ sudo vim /var/www/info.php

If you get an error, probably you don’t have installed vim on your machine. Install it or use nano instead. (for nano users, edit, save with CTRL+X and confirm with ‘Y’). In Vim, an empty text file will show up. Press a and you will enter in INSERT MODE, write the following PHP code.

phpinfo
Then press Esc and :wq which stands for “write (save) and quit”.
This simple scipt will display all informations about the current state of PHP. This includes PHP compilation options and extensions, the PHP version, server information and environment OS version information.

Finally, let’s test whether our web server can correctly display informations generated by the info.php script. Open a browser and visit the page

http://localhost/info.php

The following page will be displayed.

phpinfo1

MySQL

Reference