我正在尝试将 PHP 版本从 8.0 切换到 7.4。我运行以下命令没有成功:
sudo a2dismod php8.0
sudo a2enmod php7.4
sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)
然后,当我打开带有 PHP info 的本地网页时<?php phpinfo(); ?>,PHP 版本仍然是 8.0.3 而不是 7.4。
请注意,当我执行该命令时,sudo a2enmod php7.4我得到以下输出:
dan@dan:~$ sudo a2enmod php7.4
Considering dependency mpm_prefork for php7.4:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Enabling module mpm_prefork.
Considering conflict php5 for php7.4:
Enabling module php7.4.
To activate the new configuration, you need to run:
systemctl restart apache2
Run Code Online (Sandbox Code Playgroud)
也许这就是问题的根源?
您的系统上安装了 PHP5 吗?
您可以使用以下命令列出所有已加载的 Apache 模块apache2ctl -M:
$ sudo apache2ctl -M
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
headers_module (shared)
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php7_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
status_module (shared)
Run Code Online (Sandbox Code Playgroud)
如果您有多个php版本,请使用a2dismod禁用不需要的版本。从那里,您可以使用update-alternatives更改 PHP 的默认版本:
sudo update-alternatives --set php /usr/bin/php7.4
Run Code Online (Sandbox Code Playgroud)
注意:请务必更改
php7.4为您要使用的版本。
完成后,重新启动 Web 服务器:
sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)
这应该会给你你需要的东西。