简体   繁体   中英

Apache2 still running PHP5 when PHP7 is installed

I set up a apache2 server, and it was running PHP5. I have followed this guide to install PHP7: https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04

Now, when I run php -v I get:

PHP 7.0.30-1+ubuntu14.04.1+deb.sury.org+1 (cli) (built: May  2 2018 13:00:43) ( NTS )

However, when I made a webpage on apache and echoed phpinfo(), I got:

PHP Version 5.5.9-1ubuntu4.24

How can I tell apache2 to use PHP7?

php -v gives you the version of php-cli, to enable it in apache2 you have to run these commonads

sudo a2dismod php5
sudo a2enmod php7.0
sudo service apache2 restart

then check phpinfo() for the version. it should change.

reading more in depth the article, many people said to encouter difficulties when running $sudo apt-get install php7.0 because of "unmet dependencies". Execute the following $sudo apt-get install libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json to be sure yoo have everything needed. Good luck!

You installed new version of php for your apache2 but you will need to disable/remove sym-links to old php5.x and enable/add sym-links for new php7.x. @Rhythm Shahriar pointed that out.

But here is the full steps taken and edited from https://askubuntu.com/questions/760907/upgrade-to-16-04-php7-not-working-in-browser

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

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

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

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

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

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

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

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

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

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

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

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

Then, if needed do:

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

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

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

lrwxrwxrwx 1 root root 33 Apr 21 17:00 php7.x-cgi.conf -> ../conf-available/php7.x-cgi.conf
lrwxrwxrwx 1 root root 33 Apr 21 17:01 php7.x-fpm.conf -> ../conf-available/php7.x-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 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

Then 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.x should now be properly configured. Tested working on Ubuntu 16.04 upgraded from php5.6 to latest as of today php7.3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM