Upgrade to 16.04. php7 not working in browser
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
Related videos on Youtube
David Wright
Updated on September 18, 2022Comments
-
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 about 8 yearsThe 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 about 8 years@DougSmythies I assume you didn't read where I said you have to enable the module...
-
muru about 8 yearsUse the
a2enmod
anda2dismod
commands instead of manually tinkering with links inmods-available
/mods-enabled
(similarly,a2enconf
anda2disconf
forconf-{available,enabled}
). -
Videonauth about 8 yearsRevised my answer according to your input.
-
Doug Smythies about 8 yearsYes, I did, which is why I made the comment.
sudo a2enmod php
will not work, I tried it. Howeversudo a2enmod php7.0
will work. -
oerdnj about 8 yearsThe fiddling with links is harmful as the
a2enmod
anda2dismod
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 about 8 yearsThis should be marked as the correct answer. Ubuntu 16.04 fresh install does not include this apache2 module by default.
-
David Wright about 8 yearsI 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 about 8 yearsEXCELLENT! 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 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 almost 8 yearsWhat is the name of the "wrapper"?
-
Petar Vasilev over 7 yearsDoing just: sudo a2enmod php7.0 - did the trick for me
-
Daniel over 7 yearsThank 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 over 7 yearsI have tried several thing before and this method work for me. Thank you!!!
-
hyperGeoMetric about 7 yearsOMMFG! Of course it would be the very last comment with upvotes that finally worked for me! Thank you so mf much, @patrick!!!
-
plhn about 7 yearsOMG. You saved me.
-
petergus about 7 yearsFirst 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 over 6 yearsthis is the only solution that worked for me. cheers!
-
Artur Czyżewski about 5 yearsThis 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.