简体   繁体   中英

Trying to install php-mbstring on ubuntu 20.04

I'm just trying to create a new laravel project and faced with this message

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.

Looks like I have to install php-mbstring on my computer, so I run the command

sudo apt-get install php-mbstring 

as i found in this thread: laravel/framework requires ext-mbstring

But there is another error message

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.

This is the error code when i run 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.

What have I tried

So does anyone know how to install php-mbstring? or how can i make a laravel project?

I hope you guys can help me with this problem, please. I've been working on this problem for almost 8 hours and still can't find a solution.

Turns out i have to enabled universe repository to my system, like this

sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe"

sudo apt-get update #to update my system

As Jarad said in this thread Cannot install php-mbstring on ubuntu 18.04 . And then i can just run

sudo apt-get install php-mbstring 

But turns out, i have to be specific what version that i want to install. If i just run php-mbstring , will just install mbstring for php 8.0 not version installed on system. I have to be specific, then i run command

sudo apt-get install php7.4-mbstring 

(I moved to php7.4)

And it run perfectly. Also thank you @Nico Haase and @Peter Krebs for helping.

What works for me is to specify the version, and don't forget to update:

sudo apt update
sudo apt install php7.4-mbstring

Have you tried a system update?

sudo apt-get upgrade

I used this just today, hope it helps you as well.

I came to this issue today for php8.0-mbstring module, and I found that the correct repository i not available in my system so my method was this and it worked for me, hope it will hep you too:

sudo add-apt-repository ppa:ondrej/php

sudo apt-get install php8.0-mbstring

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM