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-php

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

Happy PHP’ing.

, , ,

10 responses to “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.

  3. Hi Adam,
    Thanks for writing me back. That is much appreciated!
    I use Arch Linux on my development server and Ubuntu on the production server.
    With Arch, updating is streamlined and easy. (With Arch, all of the current packages are updated with pacman -Syu.)

    I think you hit the nail on the head. I was trying to update without installing the mysql-php package on the Ubuntu server.
    I copied and removed the php5 directory from /etc which was causing a conflict. I then added the mysql-php package.
    I forgot that mysql-php was not included by default.
    That was my problem.

    Thanks and all best,
    Edgar Crockett

  4. I would suggest PHP-FPM instead of Apache mod_php for everything. I think it is very good that mod_php is not assumed anymore when you install PHP.

    A nice advantage of PHP-FPM is that you can run your webserver with the same user as the project files owner. This means that cache folders and uploads from the webserver result in files that have the correct owner instead of www-data. Plus, if you run multiple sites, you can isolate them from each other by running them with separate users.

  5. Or use [prebuilt] (Docker) containers which are known to work. Just install git (or whatever VCS you are using) and the editor of choice in the host.

  6. This instantly fixed my problem – thanks for the information. It took me a lot of searching before I realized the search term I needed was “rendering” !