Ubuntu 16.04 and PHP 7 not rendering

After reloading my work laptop with Ubuntu 16.04 LTS (I prefer to do a reload versus an upgrade, for each LTS version) I was very excited to install PHP 7, and installed using the standard Ubuntu repositories using typical commands:

$ sudo apt-get install apache2
$ sudo apt-get install php7.0

However, after doing the installs I discovered PHP scripts would not render in a browser. After a small amount of digging I realized that doing the base installs did not include one important piece. The package ‘libapache2-mod-php7.0’ was not automatically installed as expected, as it did in the past. (I don’t remember needing to install it separately in the past.) Hopefully the package maintainers fix this at some point. Your mileage may vary.

$ sudo apt-get install libapache2-mod-php7.0

So one quick install like shown previous and all is working fine.

Happy PHP’ing.

Published by


Application Architect from Florida

3 thoughts on “Ubuntu 16.04 and PHP 7 not rendering”

  1. I recently upgraded to 16.04 and found php not rendering properly. I asked on the “askubuntu” forum and got some suggestions about ‘mods-enabled’ and ‘conf-enabled’, which I did but it is still not working. I am very frustrated.
    I just tried your suggestion of sudo apt-get install libapache2-mod-php7.0 and am told that the latest version is already installed.
    Even after a ‘service apache2 restart’ nothing changed.


  2. @David Wright: Surely you’ve found a solution by now, but if not, here’s how I was able to solve it:

    In my fresh Ubuntu 16.04 Xenial install, the mpm_event module was enabled by default. After installing libapache2-mod-php7.0, enabling it via “a2enmod php7.0” and then restarting Apache, it complained about the PHP module not being compiled as thread-safe – meaning, it is incompatible to the MPM Apache uses by default. This leaves two options:
    a) ditch the mod_php approach and configure php-fpm instead
    b) use the mpm_prefork module

    In a production environment, I’d go the FPM route – but since this was only a development machine, I opted for the path of least resistance:

    a2dismod mpm_event
    a2enmod mpm_prefork
    service apache2 restart

    And then all worked like a charm.

    It’s a bit shameful that Ubuntu 16.04 requires so much legwork, though. That definitely wasn’t the case in previous versions, and it’s especially sad because this is an LTS. Hope they fix that in the first point release.

Leave a Reply

Your email address will not be published. Required fields are marked *