美文网首页
mac系统中使用mamp+composer.phar安装yii2

mac系统中使用mamp+composer.phar安装yii2

作者: 韩小禹 | 来源:发表于2020-11-03 23:27 被阅读0次
    • 首先电脑安装mamp集成软件
    • 把MAMP下的php复制到Mac环境变量目录,这步很关键,例如:
    # /Applications/MAMP/bin/php/php7.2.22/bin/php  是mamp中某个php版本的具体位置
    # /usr/local/bin/php72   是路径,其中php72是自己定义的名字
    
    cp /Applications/MAMP/bin/php/php7.2.22/bin/php  /usr/local/bin/php72
    
    • https://getcomposer.org/download/ 下载composer.phar,放到项目根目录。
    • 测试,输入php72 composer.phar -v之后可以看的composer版本信息
    • 将composer.phar的镜像地址改为阿里云的地址,如下所示
    php72 composer.phar config -g repo.packagist composer https://mirrors.aliyun.com/composer/
    
    • 输入php72 composer.phar config -l -g查看是否成功。
    • 使用如下命令安装yii2-mongo拓展,如下所示:
    php72 composer.phar require --prefer-dist yiisoft/yii2-mongodb
    
    • 执行完上一个命令后得到如下所示:
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - yiisoft/yii2-mongodb[2.1.0, ..., 2.1.9] require ext-mongodb >=1.0.0 -> it is missing from your system. Install or enable PHP's mongodb extension.
        - Root composer.json requires yiisoft/yii2-mongodb ^2.1 -> satisfiable by yiisoft/yii2-mongodb[2.1.0, ..., 2.1.9].
    
    To enable extensions, verify that they are enabled in your .ini files:
        - /Applications/MAMP/bin/php/php7.2.22/conf/php.ini
    You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
    
    Installation failed, reverting ./composer.json and ./composer.lock to their original content.
    
    • 提示需要在php.ini中添加mongodb extension,实际上mamp中的extension=mongodb.so是开启的。但是/Applications/MAMP/bin/php/php7.2.22/conf路径下是没有php.ini文件的。
    • 可以打开mamp软件,点击php,查看相应php版本的ini配置文件,软件中打开时会自动弹出。将php.ini中的内容复制,并在/Applications/MAMP/bin/php/php7.2.22/conf中创建一个php.ini文件,并将复制的内容粘贴进去。
    • 此时再执行命令:
    php72 composer.phar require --prefer-dist yiisoft/yii2-mongodb
    
    # 命令执行后有如下提示:
    
    Using version ^2.1 for yiisoft/yii2-mongodb
    ./composer.json has been updated
    Running composer update yiisoft/yii2-mongodb
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 1 install, 0 updates, 3 removals
      - Removing bshaffer/oauth2-server-php (v1.11.1)
      - Removing filsh/yii2-oauth2-server (v2.1.1)
      - Removing windhoney/yii2-rest-rbac (1.0.9)
      - Locking yiisoft/yii2-mongodb (2.1.9)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 0 updates, 3 removals
      - Downloading yiisoft/yii2-mongodb (2.1.9)
      - Removing windhoney/yii2-rest-rbac (1.0.9)
      - Removing filsh/yii2-oauth2-server (v2.1.1)
      - Removing bshaffer/oauth2-server-php (v1.11.1)
      - Installing yiisoft/yii2-mongodb (2.1.9): Extracting archive
    Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
    Generating autoload files
    28 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    
    • 再到项目的/vendor/yiisoft/中可以看的此时yii2-mongodb已经安装进来了。
    如果哪里看不明白或者觉得我写的不清楚,可以私信我。我是费了很大的功夫才解决的,愿意分享出来。

    相关文章

      网友评论

          本文标题:mac系统中使用mamp+composer.phar安装yii2

          本文链接:https://www.haomeiwen.com/subject/jxlwvktx.html