我使用 Ubuntu 22.04 和一个需要 PHP 5.6 的网站。但是在安装网站脚本时我收到错误:
mcrypt is not enabled on your web hosting account
为了安装mcrypt
,我使用了:
sudo apt install php5.6-mcrypt
但在 php 信息中它没有启用。我尝试了phpenmod mcrypt
,但收到类似这样的警告:
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.2/mods-available
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.0/mods-available
我没有在这些版本的 PHP 上安装 mcrypt,因此它们不是必需的。
然而似乎没有什么可以让 php5.6 mcrypt 发挥作用。
我尝试添加下面的几行,但php.ini
仍然无法解决问题。
extension=mcrypt.so
extension=php_mcrypt.dll
关于如何让 mcrypt 在 php5.6 上运行,您有什么想法吗?
我正在使用php5.6-fpm
并将其添加到虚拟主机,因此 sdomain 正在加载 php5.6。
附加信息:
inkspot@vps:~$ sudo apt install php5.6-mcrypt
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
php5.6-mcrypt is already the newest version (5.6.40-68+ubuntu22.04.1+deb.sury.or g+1).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
inkspot@vps:~$ sudo a2enmod proxy_fcgi
Considering dependency proxy for proxy_fcgi:
Module proxy already enabled
Module proxy_fcgi already enabled
inkspot@vps:~$ sudo a2enmod setenvif
Module setenvif already enabled
inkspot@vps:~$ sudo a2enconf php5.6-fpm
Enabling conf php5.6-fpm.
To activate the new configuration, you need to run:
systemctl reload apache2
inkspot@vps:~$ sudo phpenmod mcrypt
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.2/mods-available
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.2/mods-available
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.2/mods-available
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.1/mods-available
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.1/mods-available
WARNING: Module mcrypt ini file doesn't exist under /etc/php/8.1/mods-available
inkspot@vps:~$ sudo service apache2 restart
inkspot@vps:~$ sudo service php5.6-fpm restart
inkspot@vps:~$
以下是结果: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)
expires_module (shared)
fcgid_module (shared)
filter_module (shared)
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php_module (shared)
proxy_module (shared)
proxy_fcgi_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
security2_module (shared)
setenvif_module (shared)
socache_shmcb_module (shared)
ssl_module (shared)
status_module (shared)
unique_id_module (shared)
答案1
从您目前告诉我的情况来看,您可能遇到了一些旧配置文件制作问题。您提到您保留了一个旧的php.ini
。在这种情况下,最好清除所有php5.6
软件包并删除其配置。
sudo apt purge php5.6*
sudo apt autoremove
sudo rm -rf /etc/php/5.6/
在 Ubuntu 22.04 上,默认 PHP 版本是 8.2。
要在 Ubuntu 22.04 上安装php5.6-fpm
,首先您需要添加ppa:ondrej/php
存储库,因为php5.6
软件包不在官方存储库中。
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade
安装 php5.6 包:
sudo apt install php5.6
sudo apt install php5.6-fpm
sudo apt install php5.6-mcrypt
要在特定站点上启用 php5.6-fpm,您必须编辑站点的虚拟主机文件(默认值为/etc/apache2/sites-available/000-default.conf
)。在<VirtualHost *:80>
和之间</VirtualHost>
,添加以下代码:
<FilesMatch \.php$>
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/"
</If>
</FilesMatch>
启用模块和配置:
sudo a2enmod proxy_fcgi
sudo a2enmod setenvif
sudo a2enconf php5.6-fpm
sudo phpenmod mcrypt
重新启动 Apache,并且不要忘记重新启动 FPM:
sudo service apache2 restart
sudo service php5.6-fpm restart
(可选)如果您愿意,可以执行以下操作php8.2
来禁用并替换 Apache 服务器的默认 PHP 版本php5.6-fpm
:
sudo a2dismod php8.2
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo a2enconf php5.6-fpm
sudo service apache2 restart