我正在尝试在 ubuntu 20.04 上将 php7.4 从 8 降级到 php7.4。从 Digital Ocean“Marketplace”LAMP 设置全新安装。
尝试按照指南来执行此操作:
我可以像这样选择 cli php:
update-alternatives --config php
但是选择一个选项只会改变 cli php,而不是网站 php 版本。
然后我运行这个程序,尝试让 Web PHP 达到 7.4。
sudo a2enmod php7.4
> php 7.4 not installed.
然后我运行了这些命令
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt install php7.4
sudo a2enmod php7.4
systemctl restart apache2
出现错误:
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
systemctl status apache2.service
root@lamp-ubuntu-s-1vcpu-1gb-sgp1-01:/etc/apache2# systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2022-04-21 18:18:36 UTC; 27s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 45635 ExecStart=/usr/sbin/apachectl start (code=exited, status=139)
journalctl -xe
- no entries.
这里出了什么问题?我怎样才能简单地更改此服务器上网站的 php 版本?
更新:Journalctl -xe 似乎现在有内容:
-- The job identifier is 17693.
Apr 22 12:27:07 wairc-kman-1 apachectl[39336]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppre>
Apr 22 12:27:07 wairc-kman-1 kernel: apache2[39336]: segfault at 8 ip 00007f599f125215 sp 00007fff5ed2df10 error 4 in libphp7.4.so[7f599ef45000+260000]
Apr 22 12:27:07 wairc-kman-1 kernel: Code: 41 5d e9 0e fa ff ff 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 41 56 41 55 49 89 d5 41 54 49 89 f4 55 48 89 fd 53 <8b> 47 08 a8 0c 0f 85 28 01 00 0>
Apr 22 12:27:20 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=162.142.125.84 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=40 ID=64004 PROTO=TCP SPT=>
Apr 22 12:27:27 wairc-kman-1 apachectl[39330]: Segmentation fault (core dumped)
Apr 22 12:27:27 wairc-kman-1 apachectl[39330]: Action 'start' failed.
Apr 22 12:27:27 wairc-kman-1 apachectl[39330]: The Apache error log may have more information.
Apr 22 12:27:27 wairc-kman-1 systemd[1]: apache2.service: Control process exited, code=exited, status=139/n/a
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit apache2.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 139.
Apr 22 12:27:27 wairc-kman-1 systemd[1]: apache2.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit apache2.service has entered the 'failed' state with result 'exit-code'.
Apr 22 12:27:27 wairc-kman-1 systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: A start job for unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit apache2.service has finished with a failure.
--
-- The job identifier is 17693 and the job result is failed.
Apr 22 12:27:29 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=29 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:27:46 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=91.240.118.246 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=245 ID=39592 PROTO=TCP SPT>
Apr 22 12:28:05 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=71 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:28:27 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=68 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:28:44 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=162.142.125.238 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=40 ID=55003 PROTO=TCP SPT>
Apr 22 12:28:58 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=193.163.125.43 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=246 ID=18628 PROTO=TCP SPT>
Apr 22 12:29:16 wairc-kman-1 CRON[38918]: pam_unix(cron:session): session closed for user root
Apr 22 12:29:23 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=42 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:29:47 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=92.63.197.94 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=251 ID=8419 PROTO=TCP SPT=48>
Apr 22 12:30:09 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=89.248.165.97 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=250 ID=57521 PROTO=TCP SPT=>
Apr 22 12:30:21 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=91.240.118.244 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=246 ID=26437 PROTO=TCP SPT>
Apr 22 12:30:38 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:31:02 wairc-kman-1 sshd[39388]: Invalid user fin from 167.172.153.164 port 54352
Apr 22 12:31:02 wairc-kman-1 sshd[39388]: Received disconnect from 167.172.153.164 port 54352:11: Bye Bye [preauth]
Apr 22 12:31:02 wairc-kman-1 sshd[39388]: Disconnected from invalid user fin 167.172.153.164 port 54352 [preauth]
Apr 22 12:31:14 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=80.218.99.137 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=52 ID=13396 PROTO=TCP SPT=1>
Apr 22 12:31:33 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:31:48 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=41 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
lines 3243-3290/3290 (END)
systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2022-04-22 12:42:14 UTC; 9s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 39548 ExecStart=/usr/sbin/apachectl start (code=exited, status=139)
Apr 22 12:41:53 wairc-kman-1 systemd[1]: Starting The Apache HTTP Server...
Apr 22 12:42:14 wairc-kman-1 apachectl[39548]: Segmentation fault (core dumped)
Apr 22 12:42:14 wairc-kman-1 apachectl[39548]: Action 'start' failed.
Apr 22 12:42:14 wairc-kman-1 apachectl[39548]: The Apache error log may have more information.
Apr 22 12:42:14 wairc-kman-1 systemd[1]: apache2.service: Control process exited, code=exited, status=139/n/a
Apr 22 12:42:14 wairc-kman-1 systemd[1]: apache2.service: Failed with result 'exit-code'.
Apr 22 12:42:14 wairc-kman-1 systemd[1]: Failed to start The Apache HTTP Server.
设置 ServerName 127.0.0.1 以修复先前的警告后,配置测试正常
> apachectl configtest
Syntax OK
查看安装了什么 php:
update-alternatives --get-selections | grep -i php
php auto /usr/bin/php8.1
php-fpm.sock auto /run/php/php7.4-fpm.sock
phpdbg auto /usr/bin/phpdbg7.4
查看 php-fpm 选项:
update-alternatives --config php-fpm
update-alternatives: error: no alternatives for php-fpm
如果我选择 php7.4,它会显示已选择它,但运行 php-v 会显示旧值 8.1。
update-alternatives --config phar 替代 phar 有 3 个选择(提供 /usr/bin/phar)。
选择路径优先级状态
0 /usr/bin/phar8.1 81 自动模式
1 /usr/bin/phar7.4 74 手动模式 2 /usr/bin/phar8.0 80 手动模式 3 /usr/bin/phar8.1 81 手动模式
按保留当前选择[*],或输入选择编号:root@wairc-kman-1:~# php -v PHP 8.1.5 (cli) (built: Apr 21 2022 10:14:45) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.5,Copyright (c) Zend Technologies with Zend OPcache v8.1.5,Copyright (c),by Zend Technologies
答案1
我也遇到了同样的问题,你必须禁用 apache 的旧版本并激活新版本。例如:v8.1 处于活动状态,你需要降级到 v7.2。
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt install php7.2
sudo a2dismod php8.1
sudo a2enmod php7.4
systemctl restart apache2
请记住 v8.1 中激活的所有模块,并将它们与 v7.2 中的模块进行比较
答案2
运行此命令来查明 Apache 失败的原因。
journalctl -xe
最有可能的问题是您启用了多个 PHP 模块,例如启用了 php8.0,然后又启用了 php7.4。Apache 不喜欢这样。启用一个 PHP 模块。
有多个支持 Apache 的 PHP 扩展:php、php-cgi 和 php-fpm。
第一步是确定配置了哪些 PHP 安装:
update-alternatives --get-selections | grep -i php
在现代 PHP Apache 安装中,php-fpm 可能已配置。
要更改 Apache 使用的 PHP 版本,请使用以下命令:
update-alternatives --config php-fpm
另外,也可以选择更改 phar 配置:
update-alternatives --config phar
update-alternatives --config phar.phar
您还可以通过将其添加到 VirtualHost 来轻松切换 PHP 版本:
<FilesMatch \.php$>
# PHP Version 7.4
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
# PHP Version 8.0
# SetHandler "proxy:unix:/run/php/php8.0-fpm.sock|fcgi://localhost"
</FilesMatch>
列出 /run/php 目录以查看配置了哪些 PHP 套接字。
配置更改后重新启动 Apache:
systemctl restart apache2