4

After updating from ubuntu 16.04 to 18.04 I noticed that php-curl was not working, but php was working fine. I thought the problem was that apache2 was still using php7.0 instead of php7.2, so I ran

sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2

now php doesn't work, but html code is rendered...

this returns a blank page:

<?php phpinfo(); ?> 

I double-checked my implementation of phpinfo() using the version found in the php:phpinfo -manual page, repeated below, still doesn't work with apache, but it does work when I run within bash the following

my-machine:~$ php public_html/info.php

Here is an edited version of http://php.net/manual/en/function.phpinfo.php

<?php    
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>

I also tried

sudo update-alternatives --set php /usr/bin/php7.2

I've edited /etc/php/7.2/apache2/php.ini as directed in one page as follows:

short_open_tag = On

Here is some info about my setup.

php version

php -v
PHP 7.2.7-0ubuntu0.18.04.2 (cli) (built: Jul  4 2018 16:55:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.7-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies

a2query

a2query -m php7.2
php7.2 (enabled by site administrator)

list of apache2 modules, note: "AH01574: module php7_module is already loaded, skipping" is occurring because I also ran =sudo a2enmod php7.0= hoping to go back to what I thought I had... I did disable php7.2 and enable php7.0 and restart apache2 with sudo systemctl restart apache2, but php is not being rendered.

apache2ctl -M
[Sun Sep 02 18:03:43.185183 2018] [so:warn] [pid 4166] AH01574: module php7_module is already loaded, skipping
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 dnssd_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php7_module (shared)
 reqtimeout_module (shared)
 setenvif_module (shared)
 status_module (shared)
 userdir_module (shared)

list of php packages installed

sudo apt list --installed | grep -i php

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libapache2-mod-php/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
libapache2-mod-php7.0/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
libapache2-mod-php7.2/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed]
libphp-phpmailer/bionic,bionic,now 5.2.14+dfsg-2.3 all [installed,automatic]
php/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-bz2/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-cli/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-common/bionic,bionic,now 1:60ubuntu1 all [installed]
php-curl/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-db/bionic,bionic,now 1.9.2-2ubuntu1 all [installed]
php-gd/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-getid3/bionic,bionic,now 1.9.15+dfsg-1 all [installed,automatic]
php-gettext/bionic,bionic,now 1.0.12-0.1 all [installed,automatic]
php-mbstring/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-mcrypt/now 1:7.0+35ubuntu6.1 all [installed,local]
php-mysql/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-pear/bionic,bionic,now 1:1.10.5+submodules+notgz-1ubuntu1 all [installed]
php-php-gettext/bionic,bionic,now 1.0.12-0.1 all [installed,automatic]
php-phpseclib/bionic,bionic,now 2.0.9-1 all [installed,automatic]
php-tcpdf/bionic,bionic,now 6.2.13+dfsg-1ubuntu1 all [installed,automatic]
php-tidy/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-xml/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-zip/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php5-common/now 5.5.9+dfsg-1ubuntu4.19 amd64 [installed,local]
php5-json/now 1.3.2-2build1 amd64 [installed,local]
php5-mysql/now 5.5.9+dfsg-1ubuntu4.19 amd64 [installed,local]
php7.0/now 7.0.30-0ubuntu0.16.04.1 all [installed,local]
php7.0-cli/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-common/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-gd/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-json/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-mbstring/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-mcrypt/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-mysql/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-opcache/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-readline/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-xml/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.2/bionic-updates,bionic-updates,bionic-security,bionic-security,now 7.2.7-0ubuntu0.18.04.2 all [installed,automatic]
php7.2-bz2/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-cli/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-common/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-curl/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed]
php7.2-gd/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-json/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-mbstring/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-mysql/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-opcache/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-readline/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-tidy/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-xml/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-zip/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
phpmyadmin/bionic,bionic,now 4:4.6.6-5 all [installed]

apt policy libapache2-mod-php7.2

sudo apt policy libapache2-mod-php7.2
libapache2-mod-php7.2:
  Installed: 7.2.7-0ubuntu0.18.04.2
  Candidate: 7.2.7-0ubuntu0.18.04.2
  Version table:
 *** 7.2.7-0ubuntu0.18.04.2 500
        500 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
        100 /var/lib/dpkg/status
     7.2.3-1ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

ls -l /etc/apache2/mods-enabled/php*

ls -l /etc/apache2/mods-enabled/php*
lrwxrwxrwx 1 root root 29 Sep  2 18:48 /etc/apache2/mods-enabled/php7.2.conf -> ../mods-available/php7.2.conf
lrwxrwxrwx 1 root root 29 Sep  2 18:48 /etc/apache2/mods-enabled/php7.2.load -> ../mods-available/php7.2.load

sample of apache2 logs

[Mon Sep 03 00:06:52.805155 2018] [mpm_prefork:notice] [pid 5161] AH00163: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Mon Sep 03 00:06:52.805181 2018] [core:notice] [pid 5161] AH00094: Command line: '/usr/sbin/apache2'
[Sun Sep 02 13:39:30.728738 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice:  Only variables should be assigned by reference in /home/go/public_html/index.php on line 115
[Sun Sep 02 13:39:30.739232 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice:  Undefined variable: year in /home/go/public_html/calendar.php on line 38
[Sun Sep 02 13:39:30.739253 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice:  Undefined variable: month in /home/go/public_html/calendar.php on line 40
[Sun Sep 02 13:39:30.739256 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice:  Undefined variable: year in /home/go/public_html/calendar.php on line 42
[Sun Sep 02 13:39:30.739260 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice:  Undefined variable: year in /home/go/public_html/calendar.php on line 46
[Sun Sep 02 13:39:30.739278 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice:  Undefined variable: month in /home/go/public_html/calendar.php on line 52
[Sun Sep 02 13:39:30.739281 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice:  Undefined variable: month in /home/go/public_html/calendar.php on line 56
[Sun Sep 02 13:39:35.889200 2018] [:error] [pid 4111] [client 127.0.0.1:36478] PHP Notice:  Only variables should be assigned by reference in /home/go/public_html/show-reading-list.php on line 7, referer: http://localhost/~go/

variables mentioned in logs are in these php files... and I see the same errors in previous logs generated before the update.

  • 2
    Possible duplicate of PHP not working after upgraded to Ubuntu 17.10 – N0rbert Sep 3 '18 at 8:35
  • Thanks NOrbert. I checked my implementation of the phpinfo() command and updated my question with the results. phpinfo() is not rendered by apache, but returns results from bash, i.e. php public_html/info.php produces results. Starting to wonder whether I have to purge php and re-install. Any advice about how to go about that would be appreciated. – tempestcat Sep 3 '18 at 11:46
  • Do Apache logs show anything interesting? – fkraiem Sep 3 '18 at 12:24
  • I’m guessing you still get the PHP modules 7.0 and 7.2 conflicting somewhere. (Shouldn’t the packages libapache2-mod-php7.0 and libapache2-mod-php7.2 conflict with each other?) Please add the output of ls -l /etc/apache2/mods-enabled/php* to your question. – Melebius Sep 3 '18 at 12:36
2

php and php-curl are now working.

What led me to the answer is noticing a difference between php7.0.conf and php7.2.conf in /etc/apache2/mods-available/, that would only affect how php performed within the userdir. I then checked whether php worked at the server and saw that it did.

In summary, I believe that after the update from ubuntu 16.04 and 18.04 I needed to

  • disable php7.0 and enable php7.2: this created a problem with the user directory php scripts, but did fix the php-curl under the server. In other words, at this point php an php-curl was functioning at the server address;
  • edit the php7.2.conf file and comment out the <IfModule mod_userdir.c> section;
  • for those reading the entire question, I did not keep the edit to the php.ini file;
  • cleared the cache from firefox: the change did not fix the userdir problem until I did the following: open menu->preferences->privacy and security->history->use custom settings for history->clear history->settings->history->cache (all other boxes unchecked)

php and php-curl now working in userdir.

Thanks to everyone who left a comment.

0

[Adding this as answer only for ease of formatting ] I have been grappling with this problem after a fresh Ububtu18.04 install on an SSD. was Using ~/public_html directory in my user account as Document Root. No PHP code was being parsed by apache.

Finally, the detailed question above helped me determine that while php ~/public_html/test.php was working, it was only accessing php files from browser that was not working.

Solution : Allowing apache2 to execute PHP in user directories. (Just as in the answer above) . Find and edit the php7.2.conf file. In my case, it was located at /etc/apache2/mods-enabled/php7.2.conf. These lines needed to be commented out:

# Running PHP scripts in user directories is disabled by default
# 
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_flag engine Off
#    </Directory>
#</IfModule> 

Restarted apache2 and it worked now. You may need to clear the page from browser cache.

Thanks to @tempestcat Hopefully this will help other people in future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.