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

Ubuntu16.04双PHP环境下XAMPP中Composer创建Laravel项目报错

Fixing Laravel 5.4 Composer Install Error (ext-mbstring Missing) in XAMPP on Ubuntu 16.04

Alright, let's break down why you're hitting this issue and how to fix it quickly. The core problem here is that your global Composer is using the system's PHP 7.0, but you're trying to set up a Laravel 5.4 project intended to run on XAMPP's PHP 5.6. Composer is checking the system PHP's extensions instead of XAMPP's, hence the "mbstring missing" error (even if XAMPP has it enabled).

Step 1: Verify XAMPP's PHP has mbstring enabled

First, make sure XAMPP's PHP 5.6 actually has the mbstring extension turned on:

  • Option 1 (Web-based check): Start XAMPP Apache, then visit http://localhost/dashboard/phpinfo.php. Search for "mbstring" — if you see a dedicated section for it, it's enabled.
  • Option 2 (Terminal check): Run this command to list XAMPP PHP's loaded extensions:
    /opt/lampp/bin/php -m
    
    Look for mbstring in the output. If it's missing:
    1. Open /opt/lampp/etc/php.ini in a text editor (e.g., nano /opt/lampp/etc/php.ini)
    2. Find the line ;extension=mbstring.so and remove the leading semicolon (;)
    3. Save the file and restart XAMPP Apache via the control panel.

Step 2: Force Composer to use XAMPP's PHP

Since your global Composer is tied to the system's PHP 7.0, you need to tell it to use XAMPP's PHP 5.6 instead for this project. Here are three reliable ways to do this:

Method 1: Run Composer with XAMPP's PHP directly

Execute this command in your /opt/lampp/htdocs directory:

/opt/lampp/bin/php /usr/local/bin/composer create-project --prefer-dist laravel/laravel blog "5.4.*"

Note: If you're not sure where your Composer is installed, run which composer to get the correct path (replace /usr/local/bin/composer with the result).

Method 2: Temporarily prioritize XAMPP's PHP in your terminal

Run this command to update your terminal's PATH so XAMPP's PHP is used first:

export PATH=/opt/lampp/bin:$PATH

Now you can run the regular Composer command, and it will use XAMPP's PHP:

composer create-project --prefer-dist laravel/laravel blog "5.4.*"

This only lasts until you close the terminal — your system PHP will be back to default afterward.

Method 3: Permanently set Composer to use XAMPP's PHP (optional)

If you want all future Composer commands to use XAMPP's PHP, edit your Composer config:

  1. Open ~/.composer/config.json in a text editor
  2. Add or update the config section to include the PHP path:
    {
        "config": {
            "php": "/opt/lampp/bin/php"
        }
    }
    
  3. Save the file. Now every Composer command will default to XAMPP's PHP.

Step 3: Test the Laravel installation

Once the project is created, navigate to the blog directory and start the Laravel server using XAMPP's PHP to confirm everything works:

cd blog
/opt/lampp/bin/php artisan serve

Visit http://localhost:8000 in your browser — you should see the Laravel welcome page if all went well.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 06:41:36