Upgrade to 16.04. php7 not working in browser

211,190

Solution 1

Just like before, you have to install PHP for Apache.

From the Server Guide:

sudo apt install php libapache2-mod-php

That command will install PHP and the Apache 2 PHP module. Simply configure Apache as before (sudo a2enmod php7.0, I think, will turn on the module).


Your mbstring issue is similar - you need to install that extension:

sudo apt install php7.0-mbstring

For other missing modules there will be similar things to have to install as well.

Solution 2

To configure php7 to run with your server you need to do some configuration:

1. Make sure you remove any traces of php/php5

Open a terminal Ctrl+Alt+T and:

cd /etc/apache2/mods-enabled
ls -la

The output should not contain any php5.conf or php5.load, but if it does, do the following:

# this is the proper way of disabling modules
sudo a2dismod php5

# run this only if the above command didn't remove the php5 sym-links
sudo rm php5.load
sudo rm php5.conf

Now add the php7.0.conf and php7.0.load instead:

# this is the proper way of enabling modules
sudo a2enmod php7.0

# run this only if the above command didn't create the php7.0 sym-links
sudo ln -s php7.0.conf ../mods-available/php7.0.conf
sudo ln -s php7.0.load ../mods-available/php7.0.load

The output of ls -la php* should look like this:

lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.load -> ../mods-available/php7.0.load

After dealing with the modules we now come to the /etc/apache2/conf-enabled directory. Remove any traces of php/php5 here as well by sudo rm <name>

Then, if needed do:

# the proper way of enabling configs
sudo a2enconf php7.0-cgi
sudo a2enconf php7.0-fpm

# do those commands only if the above didn't work out
sudo ln -s php7.0-cgi.conf ../conf-available/php7.0-cgi.conf
sudo ln -s php7.0-fpm.conf ../conf-available/php7.0-fpm.conf

The output of ls -la php* should look like this:

lrwxrwxrwx 1 root root 33 Apr 21 17:00 php7.0-cgi.conf -> ../conf-available/php7.0-cgi.conf
lrwxrwxrwx 1 root root 33 Apr 21 17:01 php7.0-fpm.conf -> ../conf-available/php7.0-fpm.conf

2. Restarting Apache2

Before restarting Apache make sure to clean out the Apache error.log then restart:

sudo su
> /var/log/apache2/error.log
exit
sudo service apache2 restart

Now check the error.log by issuing cat /var/log/apache2/error.log | less (piping through less enables you to easy scroll up and down, q exits the output).

If your error.log contains many (and I literally mean a heap of) some MIBS not found do the following:

sudo apt install libsnmp-dev
sudo net-snmp-config --snmpconfpath
sudo apt-get install snmp snmp-mibs-downloader
sudo su
> /var/log/apache2/error.log
exit
sudo service apache2 restart

The check again the error.log it now should only contain 3 lines:

[Sat Apr 23 01:39:07.504005 2016] [mpm_prefork:notice] [pid 1647] AH00169: caught SIGTERM, shutting down
[Sat Apr 23 01:39:08.685774 2016] [mpm_prefork:notice] [pid 9590] AH00163: Apache/2.4.18 (Ubuntu) mod_perl/2.0.9 Perl/v5.22.1 configured -- resuming normal operations
[Sat Apr 23 01:39:08.685938 2016] [core:notice] [pid 9590] AH00094: Command line: '/usr/sbin/apache2'

Your Apache with php7.0 should now be properly configured.

Solution 3

I got this problem as well.

It helped me to delete all PHP and reinstall php7.

All that was needed was:

sudo apt-get purge php*

php7 will be deleted, afterwards just to reinstall:

sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi  php7.0 libapache2-mod-php7.0

Solution 4

The solution I found for this problem was the default PHP.INI setting for short_open_tag. By default this is set to 'Off'. My PHP code started with

   <?

instead of

   <?php

If enabled the short_open_tag (by changing 'Off' to 'On' in my php.ini) and reset the apache server (sudo service apache2 restart) and PHP popped back alive.

Solution 5

Im my case not only the php wasn't working but phpmyadmin aswell i did step by step like that

sudo apt install php libapache2-mod-php
sudo apt install php7.0-mbstring
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
service apache2 restart

And then to:

gksu gedit /etc/apache2/apache2.conf

In the last line I do add Include /etc/phpmyadmin/apache.conf

That make a deal with all problems

Share:
211,190

Related videos on Youtube

David Wright
Author by

David Wright

Updated on September 18, 2022

Comments

  • David Wright
    David Wright over 1 year

    I just upgraded from 14.10 to 16.04 and am not sure how to configure PHP 7 in apache. I did modify the php7.0.conf file to uncomment that last lines, restarted apache2 and no change.

    Do I need to change the apache2 setup to allow php?

    PHP works from the command line so I am sure the php is properly installed.

    Additionally, I get an error on phpadmin saying that the mbstring is missing.

  • Doug Smythies
    Doug Smythies about 8 years
    The php module should be enabled by default upon installation. If not, it has to be the full sudo a2enmod php7.0 (or so I determined by disabling and re-enabling on my computer.) interesting, I got this message: Considering conflict php5 for php7.0: Enabling module php7.0.
  • Thomas Ward
    Thomas Ward about 8 years
    @DougSmythies I assume you didn't read where I said you have to enable the module...
  • muru
    muru about 8 years
    Use the a2enmod and a2dismod commands instead of manually tinkering with links in mods-available/mods-enabled (similarly, a2enconf and a2disconf for conf-{available,enabled}).
  • Videonauth
    Videonauth about 8 years
    Revised my answer according to your input.
  • Doug Smythies
    Doug Smythies about 8 years
    Yes, I did, which is why I made the comment. sudo a2enmod php will not work, I tried it. However sudo a2enmod php7.0 will work.
  • oerdnj
    oerdnj about 8 years
    The fiddling with links is harmful as the a2enmod and a2dismod remember the state of the modules in internal apache2 package registry, so making/removing the links manually might make your system broken for future upgrades as the upgrade scripts looks at the state of this internal database.
  • Selosindis
    Selosindis about 8 years
    This should be marked as the correct answer. Ubuntu 16.04 fresh install does not include this apache2 module by default.
  • David Wright
    David Wright about 8 years
    I really appreciate your response and I have performed all of the above and everything looks as you have suggested, however apache2 is still not allowing me to run php scripts.
  • Yaniv Lankry
    Yaniv Lankry about 8 years
    EXCELLENT! I had literally a 'bastard of 3 days hell'; first mySql-server etc gave up, so my Drupal projects wouldn't work, some 3 working days later, I had to re-install, upgrade 15.10 to 16.04, then no localhost/mySql connections. I worked through your above steps, and got apache talking to my mySql DBs again. Thanks very much for taking the time for sharing it with us, just what askubuntu.com should be all about. Good karma to you.
  • d586
    d586 almost 8 years
    @David Wright - Perhaps you are trying to run PHP script from user directory - these are disabled by default. If so you need to open php7.0.conf and comment out the last part. More here devplant.net/2010/05/04/…
  • EKons
    EKons almost 8 years
    What is the name of the "wrapper"?
  • Petar Vasilev
    Petar Vasilev over 7 years
    Doing just: sudo a2enmod php7.0 - did the trick for me
  • Daniel
    Daniel over 7 years
    Thank you very much. This line: sudo apt install libsnmp-dev was missing element in my case. I was searching this a lot of time. You are awesome!
  • Srikanth Ponnapalli
    Srikanth Ponnapalli over 7 years
    I have tried several thing before and this method work for me. Thank you!!!
  • hyperGeoMetric
    hyperGeoMetric about 7 years
    OMMFG! Of course it would be the very last comment with upvotes that finally worked for me! Thank you so mf much, @patrick!!!
  • plhn
    plhn about 7 years
    OMG. You saved me.
  • petergus
    petergus about 7 years
    First class!! I tried many other solutions all over the net, with a fresh install of Ubuntu 16 and Viritual min. This worked! Thank you!
  • geevee
    geevee over 6 years
    this is the only solution that worked for me. cheers!
  • Artur Czyżewski
    Artur Czyżewski about 5 years
    This helped me, cause after Ubuntu upgrade I didnt found php7.0-cgi in conf-avaliable. BUT keep in mind that doing sudo apt-get purge php* will remove your phpMyAdmin also, if you have one.