9

I've just upgraded to Ubuntu 18.04. Now apache serves my website's php as plaintext php. I've already tried: Why are my PHP files showing as plain text? (on Stack Overflow) and PHP 7 and apache displays plain text and cannot be restarted. The installed php packages are:

php              php7.2-cli       php7.2-fpm       php7.2-mbstring  php7.2-pgsql     php7.2-sqlite3   php7.2-zip       php-curl         php-igbinary     php-pgsql        php-xml
php7.2           php7.2-common    php7.2-gd        php7.2-mysql     php7.2-readline  php7.2-xml       php-bz2          php-fpm          php-mbstring     php-soap         php-xmlrpc
php7.2-bz2       php7.2-curl      php7.2-json      php7.2-opcache   php7.2-soap      php7.2-xmlrpc    php-common       php-gd           php-mysql        php-sqlite3      php-zip

One of the websites in question can be seen here.

The apache error.log:

[Thu Apr 26 16:02:12.740886 2018] [mpm_prefork:notice] [pid 6504] AH00169: caught SIGTERM, shutting down

[Thu Apr 26 16:02:13.001806 2018] [mpm_prefork:notice] [pid 7704] AH00163: Apache/2.4.29 (Ubuntu) OpenSSL/1.1.0g configured -- resuming normal operations

[Thu Apr 26 16:02:13.001900 2018] [core:notice] [pid 7704] AH00094: Command line: '/usr/sbin/apache2'

And the access.log:

<MYIP> - - [26/Apr/2018:16:02:40 +0200] "-" 408 3435 "-" "-"

<MYIP> - - [26/Apr/2018:16:02:40 +0200] "-" 408 3435 "-" "-"

<MYIP> - - [26/Apr/2018:16:02:40 +0200] "-" 408 3435 "-" "-"
Zanna
  • 72,312

4 Answers4

24

This is what got my installation sorted

sudo apt install php7.2 php7.2-common php7.2-cli
sudo a2enmod php7.2
Phippsy
  • 376
6

Actually, in addition to the commands in this answer, you need

sudo apt install libapache2-mod-php

as well. Somehow it has disappeared!

Zanna
  • 72,312
Jarek
  • 161
  • 1
  • 4
0

It looks like this might be related to having 2 versions of PHP installed and enabled at the same time after the upgrade. Neither of the above worked for me, so I uninstalled Apache, PHP 7.1 and PHP 7.2, reinstalled Apache and PHP 7.2 and things are working now.

0

I ran into this while upgrading from Ubuntu 16.04.6 LTS to 18.04 LTS using the do-release-upgrade tool. In my case the following helped:

sudo apt-get install php7.2 libapache2-mod-php

This added libapache2-mod-php7.2 as well. php7.2-common and php7.2-cli were already installed, so they were ignored. sudo a2enmod php7.2 was executed automatically by apt-get.

BTW, you can diagnose this problem by creating a file /var/www/html/phpinfo.phpwith the following contents:

<?php phpinfo(); ?>

and then pointing your browser to the URL http://your.server/phpinfo.php. You should get a nice webpage with all the PHP settings. If you get the <?php phpinfo(); ?> text instead then you need to install the packages described above.

I am mentioning this because first I just ran php -v on the command line and it told me that PHP 7.2 was installed. Which is sort-of true (as the command-line stuff from the package php7.2-cli was indeed installed), but it's not the whole story. :-)