PHP rendered as text after Ubuntu 16.04 upgrade

The php command is provided by php7.0-cli package on Ubuntu 16.04. Running the CLI is orthogonal to the web server configuration.

You need to install and configure one of the web SAPIs - apache2, fpm or cgi. The most easy is to install apache2 SAPI.

  1. To install apache2 SAPI, run apt-get install libapache2-mod-php (this will pull the default PHP version, currently libapache2-mod-php7.0). The package should enable itself and switch to apache2 prefork MPM that's the only MPM supported. If not, try to run a2enmod php7.0 and look for errors. The installation should switch from event MPM to prefork MPM automatically, but if it doesn't, you can switch it manually by doing sudo a2dismod mpm_event followed by sudo a2enmod mpm_prefork.

  2. To install FPM SAPI, run apt-get install php-fpm and then enable FPM by running a2enconf php7.0-fpm. The FPM SAPI is more secure, but harder to configure correctly.

  3. To install CGI SAPI, run apt-get install php-cgi and then enable CGI by running a2enconf php7.0-cgi. Please not that CGI is not recommended way how to run PHP, but it might come handy in special deployments.