Deepin系统PHP8.2-mbstring安装失败及Laravel Breeze报错求助
问题描述
1. 安装php8.2-mbstring时的依赖错误
执行命令sudo apt-get install php8.2-mbstring后,出现以下错误:
SYED_AMIR_ALI@amirali:~$ sudo apt-get install php8.2-mbstring [sudo] password for SYED_AMIR_ALI: Verification successful Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: php8.2-mbstring : Depends: libonig4 (>= 5.9.5) but it is not installable E: Unable to correct problems, you have held broken packages.
2. Laravel Breeze安装时的函数未定义错误
因缺少mbstring扩展,执行composer require laravel/breeze --dev后运行php artisan breeze:install,出现错误:
SYED_AMIR_ALI@amirali:~/Desktop/laravel-rtk-query$ php artisan breeze:install Which stack would you like to install? Error Call to undefined function Termwind\ValueObjects\mb_strimwidth() at vendor/nunomaduro/termwind/src/ValueObjects/Styles.php:1053 1049▕ */ private static function trimText(string $text, int $width): string { preg_match_all(self::STYLING_REGEX, $text, $matches, PREG_OFFSET_CAPTURE); $text = rtrim(mb_strimwidth(preg_replace(self::STYLING_REGEX, '', $text) ?? '', 0, $width, '', 'UTF-8')); foreach ($matches[0] ?? [] as [$part, $index]) { $text = substr($text, 0, $index).$part.substr($text, $index, null); } +4 vendor frames 5 [internal]:0 Termwind\Components\Element::__toString() +23 vendor frames 29 artisan:35 Illuminate\Foundation\Console\Kernel::handle()
解决方法
方法一:手动解决libonig4依赖后安装mbstring
查看系统架构:
dpkg --print-architecture获取对应架构的libonig4 deb包(从Debian同版本官方软件仓库中获取),执行本地安装:
sudo dpkg -i libonig4_*.deb修复可能的依赖问题:
sudo apt-get install -f再次安装php8.2-mbstring:
sudo apt-get install php8.2-mbstring
方法二:通过PECL编译安装mbstring扩展
如果无法获取libonig4包,可采用编译安装方式:
安装编译依赖:
sudo apt-get install php8.2-dev libonig-dev使用PECL安装mbstring:
pecl install mbstring在PHP配置文件中启用扩展:
编辑php.ini文件(可通过php --ini查看配置文件路径),添加一行:extension=mbstring.so重启PHP服务(根据你的环境选择命令):
sudo systemctl restart php8.2-fpm
sudo systemctl restart apache2
验证扩展安装成功
执行命令查看已安装的PHP扩展:php -m | grep mbstring
若输出mbstring,说明扩展已生效。
重新运行Laravel Breeze安装
回到Laravel项目目录,执行:php artisan breeze:install
内容的提问来源于stack exchange,提问作者Mohammad Amir

