You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel提示需Mcrypt PHP扩展问题求助(XAMPP环境)

解决Laravel提示"requires the Mcrypt PHP extension"的问题

Hey, I’ve dealt with this exact issue a bunch of times—Laravel’s older versions rely on the Mcrypt PHP extension, and updating Composer won’t fix it because Composer manages your project dependencies, not the core PHP extensions your system needs. Let’s walk through how to get this sorted based on your operating system:

Windows系统

  • 如果你用的是WAMP/XAMPP这类集成环境:
    1. 找到PHP配置文件php.ini(一般在集成环境的php目录下)
    2. 找到;extension=mcrypt这一行,去掉开头的分号来取消注释
    3. 重启你的Web服务器(Apache/Nginx)或者Laravel内置服务器
  • 如果你是手动安装的PHP:
    1. 下载和你的PHP版本、架构(32/64位)、线程安全状态匹配的Mcrypt扩展
    2. 将扩展文件放到PHP的ext目录中
    3. 在php.ini里添加extension=mcrypt.dll
    4. 重启服务器

Ubuntu/Debian系统

打开终端执行以下命令:

  • 安装Mcrypt扩展(可以指定PHP版本,比如PHP7.4就用php7.4-mcrypt):
    sudo apt update
    sudo apt install php-mcrypt
    
  • 重启Web服务器生效:
    sudo systemctl restart apache2  # 用Nginx的话替换成nginx
    
  • 如果用的是Laravel内置服务器,先关闭再重新启动php artisan serve

CentOS/RHEL系统

在终端执行:

  • 先安装EPEL仓库(如果还没装的话):
    sudo yum install epel-release
    
  • 安装Mcrypt扩展:
    sudo yum install php-mcrypt
    
  • 重启Apache:
    sudo systemctl restart httpd
    

验证扩展是否生效的小技巧

  • 在终端执行php -m,查看输出列表里有没有mcrypt
  • 或者创建一个phpinfo.php文件,内容写<?php phpinfo(); ?>,通过浏览器访问这个文件,搜索"mcrypt"确认是否启用

最后提一句:如果你用的是PHP7.2及以上版本,Mcrypt已经被官方弃用了。如果条件允许,你可以考虑把Laravel升级到不依赖Mcrypt的新版本,但要先测试和你的图书馆管理系统的兼容性哦。

内容的提问来源于stack exchange,提问作者Murtaza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:02:32