简体   繁体   English

安装PHP7后,Apache2仍在运行PHP5

[英]Apache2 still running PHP5 when PHP7 is installed

I set up a apache2 server, and it was running PHP5. 我设置了一个apache2服务器,它正在运行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 我已按照此指南安装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 -v时,我得到:

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: 但是,当我在apache上制作一个网页并回显phpinfo()时,我得到了:

PHP Version 5.5.9-1ubuntu4.24

How can I tell apache2 to use PHP7? 如何告诉apache2使用PHP7?

php -v gives you the version of php-cli, to enable it in apache2 you have to run these commonads php -v为您提供了php-cli的版本,要在apache2中启用它,您必须运行以下commonads

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

then check phpinfo() for the version. 然后检查phpinfo()的版本。 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". 更深入地阅读该文章,许多人说在运行$sudo apt-get install php7.0因为“未满足的依赖性”。 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. 执行以下$sudo apt-get install libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json以确保您拥有所需的一切。 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. 您为apache2安装了新版本的php,但您需要禁用/删除到旧php5.x的符号链接,并启用/添加新php7.x的符号链接。 @Rhythm Shahriar pointed that out. @节奏Shahriar指出。

But here is the full steps taken and edited from https://askubuntu.com/questions/760907/upgrade-to-16-04-php7-not-working-in-browser 但是这里是从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: 要将php7.x配置为与apache2服务器一起运行,您需要进行一些配置:

1. Make sure you remove any traces of php/php5.x 1.确保您删除了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: 输出不应包含任何php5.x.confphp5.x.load ,但如果包含,请执行以下操作:

# 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: 现在添加php7.x.confphp7.x.load代替:

# 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: ls -la php*的输出应如下所示:

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. 处理完模块之后,我们现在进入/etc/apache2/conf-enabled目录。 Remove any traces of php/php5.x here as well by sudo rm <name> 通过sudo rm <name>也在此处删除任何php / php5.x的痕迹

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: ls -la php*的输出应如下所示:

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 2.重新启动Apache2

Before restarting Apache make sure to clean out the Apache error.log then restart: 重新启动Apache之前,请确保清除Apache error.log然后重新启动:

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检查error.log 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). cat /var/log/apache2/error.log | less (通过更少的管道滚动,您可以轻松地上下滚动, q退出输出)。

If your error.log contains many (and I literally mean a heap of) some MIBS not found do the following: 如果您的error.log包含许多(实际上是一堆MIBS not found请执行以下操作:

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: 然后再次检查error.log ,现在它应该只包含3行:

[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. 现在应该正确配置带有php7.x的Apache。 Tested working on Ubuntu 16.04 upgraded from php5.6 to latest as of today php7.3 经过测试,可以在Ubuntu 16.04上从php5.6升级到最新的php7.3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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