并行运行 PHP5.6 和 PHP7.2 - 切换到 5.6(仅适用于 apache2)不起作用

Posted

技术标签:

【中文标题】并行运行 PHP5.6 和 PHP7.2 - 切换到 5.6(仅适用于 apache2)不起作用【英文标题】:Run PHP5.6 and PHP7.2 in parallel - switching to 5.6 (only for apache2) doesn't work 【发布时间】:2018-09-04 08:47:16 【问题描述】:

按照本教程在php版本之间切换:(7.2和5.6):

http://mehedi.info/2017/06/07/use-php-5-6-php-7-0-alongside-one-another-ubuntu/

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6 php5.6-mysql php5.6-mbstring libapache2-mod-php5.6

从php5.6到php7.2:

sudo a2dismod php5.6 ; sudo a2enmod php7.2 ; sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php7.2

从php7.2到php5.6:

sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php5.6

在终端中运行sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart 时出现此错误:

模块 php7.2 已禁用考虑依赖 mpm_prefork 为 php5.6:考虑冲突mpm_event for mpm_prefork:考虑 mpm_prefork 的冲突 mpm_worker:模块 mpm_prefork 已经 启用考虑冲突 php5 与 php5.6:模块 php5.6 已经 enabled Job for apache2.service 失败,因为控制过程 退出并显示错误代码。请参阅“systemctl status apache2.service”和 “journalctl -xe”了解详情。

是我从systemctl status apache2.service得到的:

● apache2.service - The Apache HTTP Server    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf    Active: failed (Result: exit-code) since Mon 2018-03-26 10:56:51 IDT; 38min ago   Process: 18615 ExecStop=/usr/sbin/apachectl stop (code=exited, status=139)   Process: 18891 ExecStart=/usr/sbin/apachectl start (code=exited, status=139)  Main PID: 18540 (code=exited, status=0/SUCCESS)

Mar 26 10:56:51 Company systemd[1]: Starting The Apache HTTP Server...
Mar 26 10:56:51 Company apachectl[18891]: Segmentation fault (core dumped)
Mar 26 10:56:51 Company apachectl[18891]: Action 'start' failed.
Mar 26 10:56:51 Company apachectl[18891]: The Apache error log may have more information.
Mar 26 10:56:51 Company systemd[1]: apache2.service: Control process exited, code=exited status=139
Mar 26 10:56:51 Company systemd[1]: Failed to start The Apache HTTP Server.
Mar 26 10:56:51 Company systemd[1]: apache2.service: Unit entered failed state.
Mar 26 10:56:51 Company systemd[1]: apache2.service: Failed with result 'exit-code'.

这是来自systemctl status apache2.service

-- 
-- The start-up result is done.
Mar 26 11:33:45 Company nm-dispatcher[20168]: req:1 'dhcp4-change' [wlp3s0]: new request (1 scripts)
Mar 26 11:33:45 Company nm-dispatcher[20168]: req:1 'dhcp4-change' [wlp3s0]: start running ordered s
Mar 26 11:33:45 Company kernel: userif-4: sent link down event.
Mar 26 11:33:45 Company kernel: userif-4: sent link up event.
Mar 26 11:33:52 Company vmnet-dhcpd[2740]: DHCPREQUEST for 192.168.90.128 from 00:0c:29:71:c5:c9 via
Mar 26 11:33:52 Company vmnet-dhcpd[2740]: DHCPACK on 192.168.90.128 to 00:0c:29:71:c5:c9 via vmnet8
Mar 26 11:34:01 Company CRON[20179]: pam_unix(cron:session): session opened for user username by (uid=0
Mar 26 11:34:01 Company CRON[20180]: (username) CMD (/home/username/collectit/bin/collectit.sh >>/tmp/coll
Mar 26 11:34:01 Company CRON[20179]: (CRON) info (No MTA installed, discarding output)
Mar 26 11:34:01 Company CRON[20179]: pam_unix(cron:session): session closed for user username
Mar 26 11:35:01 Company CRON[20202]: pam_unix(cron:session): session opened for user username by (uid=0
Mar 26 11:35:01 Company CRON[20203]: (username) CMD (/home/username/collectit/bin/collectit.sh >>/tmp/coll
Mar 26 11:35:01 Company CRON[20202]: (CRON) info (No MTA installed, discarding output)
Mar 26 11:35:01 Company CRON[20202]: pam_unix(cron:session): session closed for user username
Mar 26 11:36:01 Company CRON[20235]: pam_unix(cron:session): session opened for user username by (uid=0
Mar 26 11:36:01 Company CRON[20236]: (username) CMD (/home/username/collectit/bin/collectit.sh >>/tmp/coll
Mar 26 11:36:01 Company CRON[20235]: (CRON) info (No MTA installed, discarding output)
Mar 26 11:36:01 Company CRON[20235]: pam_unix(cron:session): session closed for user username

我已经用干净的新操作系统(虚拟机)测试了确切的过程,并得到了完全相同的错误。

【问题讨论】:

有什么写给/var/log/apache2/error.log的吗? 我发现这个问题与您的问题相似。 ***.com/questions/42619312/… 并检查此链接以查找您的 apache 错误 askubuntu.com/questions/629995/apache-not-able-to-restart 如果您所做的只是改变 apache2 的用途,您无需担心sudo update-alternatives。我使用该 ppa 和 sudo a2dismod php7.? sudo a2enmod php7.? 在 7.0、7.1 和 7.2 之间切换,没有任何问题。所以我想知道你是否启用了与php5.6不兼容的mod或配置。 @RaviHirani 我已经尝试了这些帖子中提到的所有方法,除了包括重新安装 apache2 在内的方法——这对我来说将是一团糟 对。 update-alternatives 与您的问题无关。这就是我想说的。 【参考方案1】:

您可以为每个虚拟主机定义不同的 FastCgi 服务路径

<VirtualHost *:80> DocumentRoot /var/www <FilesMatch \.php$> SetHandler "proxy:unix:path/to/php-fpm-version.sock|fcgi://localhost" </FilesMatch> </VirtualHost>

【讨论】:

这也应该适用于常见的 apache 模块。不需要 FastCGI

以上是关于并行运行 PHP5.6 和 PHP7.2 - 切换到 5.6(仅适用于 apache2)不起作用的主要内容,如果未能解决你的问题,请参考以下文章

一文彻底解决Ubuntu上PHP的安装以及版本切换

修改.htaccess以使用php7.2而不是php5.6后出现500错误[重复]

linux 安装多个PHP版本(php5.6 php7.1 php7.2 php7.3 php7.4 php8.0)nginx配置php多版本

不同端口的虚拟主机和窗口主机

php5.6+Redis+Windows7安装 (phpstudy)

mac使用php-version切换PHP版本