V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
q569321245
V2EX  ›  PHP

使用 composer 安装 MixPHP 遇到提示 PHP 缺少扩展 很诡异

  •  
  •   q569321245 · 2019-11-01 15:51:59 +08:00 · 5631 次点击
    这是一个创建于 1877 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Do not run Composer as root/super user! See https://getcomposer.org/root for details
    Installing mix/mix (v2.0.7)
      - Installing mix/mix (v2.0.7): Loading from cache
    Created project in /home/wwwroot/mix
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - The requested PHP extension ext-redis * is missing from your system. Install or enable PHP's redis extension.
      Problem 2
        - The requested PHP extension ext-mbstring * is missing from your system. Install or enable PHP's mbstring extension.
    
    但是我本地输出 phpinfo() 跟 执行 php -m 都有这两个扩展
    我也本地测试 redis
    $redis = new Redis() or die("Cannot load Redis module.");
    $redis->connect('localhost',6379);
    $auth = $redis->auth('redis');//redis 改为你的 redis 密码
    $redis->set('name', '111');
    echo $redis->get('name');
    结果是输出 111
    
    求各位大佬支个招
    
    12 条回复    2019-11-02 09:40:48 +08:00
    2kCS5c0b0ITXE5k2
        1
    2kCS5c0b0ITXE5k2  
       2019-11-01 15:58:42 +08:00 via iPhone
    确认下 composer 用的 PHP 和你测试的是否一样
    q569321245
        2
    q569321245  
    OP
       2019-11-01 16:02:20 +08:00
    @emeab composer 使用的是“环境变量”里面的 php php -v 跟我 phpinfo 输出出来的 php 是一个版本的
    haiyang416
        3
    haiyang416  
       2019-11-01 16:24:12 +08:00
    php composer.phar install 试试,仔细检查下 composer 运行的到底是那个 php,加载的是哪个 php.ini 。
    q569321245
        4
    q569321245  
    OP
       2019-11-01 16:52:39 +08:00
    @haiyang416 执行 php composer.phar install 报错 Could not open input file: composer.phar
    问下怎么检查 composer 运行的到底是那个 php,加载的是哪个 php.ini 步骤要怎么去实现
    littleylv
        5
    littleylv  
       2019-11-01 16:58:22 +08:00
    首先确认 composer 的 php 和你直接执行的 php 是不是同一个
    `which composer` 找到对应的 composer 执行文件,打开看看第一行类似这样的 `#!/usr/bin/env php`
    执行第一行里的 `/usr/bin/env php -v (-m)` 看看和`php -v (-m)`的一样不

    或者执行 `composer show -p` 看看
    q569321245
        6
    q569321245  
    OP
       2019-11-01 17:50:54 +08:00
    @littleylv 查出来确实 php 跟 php -v 的不一样 那要怎么去切换 composer 的 php 版本呢
    littleylv
        7
    littleylv  
       2019-11-01 18:01:59 +08:00
    @q569321245 #6 那简单,就是跟 @haiyang416 #3 说的一样,指定 php

    /path/to/php /path/to/composer install xxx

    /usr/bin/php /usr/local/bin/composer show -p 比如我这样执行的就是 macOS 自带的 php7.3.8
    /usr/local/bin/php /usr/local/bin/composer show -p (或者不指定路径就是默认的 php /usr/local/bin/composer show -p 或者 composer show -p )就是执行 brew 安装的 php7.3.11
    q569321245
        8
    q569321245  
    OP
       2019-11-01 18:05:53 +08:00
    @littleylv 我刚才试下了 /path/to/php(有 redis.mbstring 扩展的 php) composer create-project mix/mix --prefer-dist 还是会报错
    littleylv
        9
    littleylv  
       2019-11-01 18:08:03 +08:00
    Could not open input file: composer 吗?
    那肯定的呀,你这个时候执行的是 php,后面得跟 php 文件,所以需要 /path/to/composer 而不是 composer
    具体 composer 路径 `which composer`


    /path/to/php /path/to/composer install xxx
    q569321245
        10
    q569321245  
    OP
       2019-11-01 18:21:45 +08:00
    @littleylv 不是 是报缺少扩展
    skiy
        11
    skiy  
       2019-11-01 20:21:07 +08:00 via Android
    macos?你确认一下是否搞了两个 php
    q569321245
        12
    q569321245  
    OP
       2019-11-02 09:40:48 +08:00
    sudo /usr/local/bin/composer create-project mix/mix --prefer-dist 执行这条语句报了下面的错
    Your requirements could not be resolved to an installable set of packages.

    Problem 1
    - The requested PHP extension ext-redis * is missing from your system. Install or enable PHP's redis extension.
    Problem 2
    - The requested PHP extension ext-mbstring * is missing from your system. Install or enable PHP's mbstring extension.


    但是我打印 /usr/local/bin/composer show -p
    composer-plugin-api 1.1.0 The Composer Plugin API
    ext-amqp 1.9.3 The amqp PHP extension
    ext-bcmath 7.1.0 The bcmath PHP extension
    ext-ctype 7.1.0 The ctype PHP extension
    ext-curl 7.1.0 The curl PHP extension
    ext-date 7.1.0 The date PHP extension
    ext-dom 20031129 The dom PHP extension
    ext-fileinfo 1.0.5 The fileinfo PHP extension
    ext-filter 7.1.0 The filter PHP extension
    ext-ftp 7.1.0 The ftp PHP extension
    ext-gd 7.1.0 The gd PHP extension
    ext-gettext 7.1.0 The gettext PHP extension
    ext-hash 1.0 The hash PHP extension
    ext-iconv 7.1.0 The iconv PHP extension
    ext-json 1.5.0 The json PHP extension
    ext-libxml 7.1.0 The libxml PHP extension
    ext-mbstring 7.1.0 The mbstring PHP extension
    ext-mcrypt 7.1.0 The mcrypt PHP extension
    ext-mysqli 7.1.0 The mysqli PHP extension
    ext-mysqlnd 0 The mysqlnd PHP extension (actual version: mysqlnd 5.0.12-dev - 20150407 - $Id: d8daadaf41e3cd81d7c6ae96c6091fd15b2c9382 $)
    ext-openssl 7.1.0 The openssl PHP extension
    ext-pcre 7.1.0 The pcre PHP extension
    ext-PDO 7.1.0 The PDO PHP extension
    ext-pdo_mysql 7.1.0 The pdo_mysql PHP extension
    ext-pdo_sqlite 7.1.0 The pdo_sqlite PHP extension
    ext-Phar 2.0.2 The Phar PHP extension
    ext-posix 7.1.0 The posix PHP extension
    ext-redis 4.0.2 The redis PHP extension
    ext-Reflection 7.1.0 The Reflection PHP extension
    ext-session 7.1.0 The session PHP extension
    ext-SimpleXML 7.1.0 The SimpleXML PHP extension
    ext-soap 7.1.0 The soap PHP extension
    ext-sockets 7.1.0 The sockets PHP extension
    ext-SPL 7.1.0 The SPL PHP extension
    ext-sqlite3 0.7-dev The sqlite3 PHP extension
    ext-swoole 1.9.1 The swoole PHP extension
    ext-tokenizer 7.1.0 The tokenizer PHP extension
    ext-xapian 0 The xapian PHP extension (actual version: )
    ext-xdebug 2.6.0beta1 The xdebug PHP extension
    ext-xml 7.1.0 The xml PHP extension
    ext-xmlreader 7.1.0 The xmlreader PHP extension
    ext-xmlwriter 7.1.0 The xmlwriter PHP extension
    ext-Zend-OPcache 7.1.0 The Zend OPcache PHP extension
    ext-zip 1.13.5 The zip PHP extension
    ext-zlib 7.1.0 The zlib PHP extension
    lib-curl 7.47.0 The curl PHP library
    lib-iconv 2.23 The iconv PHP library
    lib-libxml 2.9.3 The libxml PHP library
    lib-openssl 1.0.2.7 OpenSSL 1.0.2g 1 Mar 2016
    lib-pcre 8.38 The pcre PHP library
    php 7.1.0 The PHP interpreter
    php-64bit 7.1.0 The PHP interpreter, 64bit
    php-ipv6 7.1.0 The PHP interpreter, with IPv6 support


    里面显示的 php 版本也是 7.1.0 跟我 PHP -V 的版本是一样的
    PHP 7.1.0 (cli) (built: Nov 5 2018 16:01:57) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.1.0, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.6.0beta1, Copyright (c) 2002-2017, by Derick Rethans

    昨天根据大家说的装了两个 php 把其中一个给删除了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2931 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:19 · PVG 16:19 · LAX 00:19 · JFK 03:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.