尝试在 ubuntu 20.04 上安装 php-mbstring
Posted
技术标签:
【中文标题】尝试在 ubuntu 20.04 上安装 php-mbstring【英文标题】:Trying to install php-mbstring on ubuntu 20.04 【发布时间】:2021-10-03 08:03:58 【问题描述】:我只是想创建一个新的 laravel 项目并遇到此消息
Creating a "laravel/laravel" project at "./example-app"
Installing laravel/laravel (v8.5.22)
- Installing laravel/laravel (v8.5.22): Extracting archive
Created project in /home/alifirhas/0_Work/Belajar/postgresql/example-app
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- laravel/framework[v8.40.0, ..., 8.x-dev] require ext-mbstring * -> it is missing from your system. Install or enable PHP's mbstring extension.
- Root composer.json requires laravel/framework ^8.40 -> satisfiable by laravel/framework[v8.40.0, ..., 8.x-dev].
To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/8.0/cli/php.ini
- /etc/php/8.0/cli/conf.d/10-opcache.ini
- /etc/php/8.0/cli/conf.d/10-pdo.ini
- /etc/php/8.0/cli/conf.d/20-calendar.ini
- /etc/php/8.0/cli/conf.d/20-ctype.ini
- /etc/php/8.0/cli/conf.d/20-exif.ini
- /etc/php/8.0/cli/conf.d/20-ffi.ini
- /etc/php/8.0/cli/conf.d/20-fileinfo.ini
- /etc/php/8.0/cli/conf.d/20-ftp.ini
- /etc/php/8.0/cli/conf.d/20-gettext.ini
- /etc/php/8.0/cli/conf.d/20-iconv.ini
- /etc/php/8.0/cli/conf.d/20-phar.ini
- /etc/php/8.0/cli/conf.d/20-posix.ini
- /etc/php/8.0/cli/conf.d/20-readline.ini
- /etc/php/8.0/cli/conf.d/20-shmop.ini
- /etc/php/8.0/cli/conf.d/20-sockets.ini
- /etc/php/8.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/8.0/cli/conf.d/20-sysvsem.ini
- /etc/php/8.0/cli/conf.d/20-sysvshm.ini
- /etc/php/8.0/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
看来我必须在我的电脑上安装 php-mbstring,所以我运行命令
sudo apt-get install php-mbstring
我在这个帖子中发现:laravel/framework requires ext-mbstring
但是还有另一个错误信息
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:
php-mbstring : Depends: php8.0-mbstring but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
这是我运行sudo apt install php7.4-mbstring
时的错误代码
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:
php7.4-mbstring : Depends: libonig5 (>= 6.8.1) but it is not installable
E: Unable to correct problems, you have held broken packages.
我尝试了什么
在我的电脑上重新安装了php7.4然后尝试安装mbstring,但是失败了 将我的php版本更新到版本-8,然后尝试安装mbstring,但失败 执行此线程中的操作:https://askubuntu.com/questions/1064634/unable-to-install-php-mbstring,但失败那么有人知道如何安装 php-mbstring 吗?或者我该如何做一个 laravel 项目?
我希望你们能帮我解决这个问题,拜托。我已经解决这个问题将近 8 个小时,但仍然找不到解决方案。
【问题讨论】:
如果您使用的是 PHP 8,如第一个屏幕中的其他扩展列表所示,为什么不使用apt install php8.0-mbstring
?
【参考方案1】:
对我有用的是指定版本,不要忘记更新:
sudo apt update
sudo apt install php7.4-mbstring
您尝试过系统更新吗?
sudo apt-get upgrade
我今天才用这个,希望对你也有帮助。
【讨论】:
【参考方案2】:原来我必须像这样为我的系统启用 Universe 存储库
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe"
sudo apt-get update #to update my system
正如 Jarad 在此线程 Cannot install php-mbstring on ubuntu 18.04 中所说。然后我就可以跑了
sudo apt-get install php-mbstring
但事实证明,我必须具体说明我要安装的版本。如果我只是运行php-mbstring
,只会为 php 8.0 安装 mbstring,而不是系统上安装的版本。我必须具体,然后我运行命令
sudo apt-get install php7.4-mbstring
(我搬到了php7.4)
它运行完美。还要感谢 @Nico Haase 和 @Peter Krebs 的帮助。
【讨论】:
以上是关于尝试在 ubuntu 20.04 上安装 php-mbstring的主要内容,如果未能解决你的问题,请参考以下文章
在 ubuntu 20.04LTS 上安装 pygame 的问题
如何在 Ubuntu 20.04 GCP 实例上安装 virtualenv?
如何在 ubuntu 20.04 上安装 python3-pip
无法在 Ubuntu 20.04 上安装 ROS Melodic