作曲家赛格温 [英] Composer & Cygwin

查看:23
本文介绍了作曲家赛格温的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您尝试全局"安装 Composer,它无法在 Cygwin 中正确运行.

Composer doesn't run correctly in Cygwin if you try to install it "globally".

将composer.phar放入/usr/local/bin/composer,然后尝试运行会报错:

Putting composer.phar into /usr/local/bin/composer, then trying to run it will result in the error:

Could not open input file: /usr/local/bin/composer

推荐答案

刚刚遇到同样的问题,找到了解决方案.把它贴在这里,以防万一我不得不再次查找它.

Just tripped over the same problem and found a solution. Posting it here, just in case I'll ever have to look it up again.

  1. /home/my-username下建立一个bin目录:

cd ~
mkdir bin

  • 移动 composer.phar(或任何其他正在兴起的漂亮新 PHP 小鬼)进入~/bin目录并确保设置它的执行位:

  • Move the composer.phar (or any other of those nifty new PHP imps that are on the rise) into the ~/bindirectory and make sure to set it's execution bit:

    # Notice how I got rid of the superfluous `.phar` extension
    mv /path/to/composer.phar ~/bin/composer
    chmod +x ~/bin/composer
    

  • 告诉 cygwin 在搜索路径中包含你的 ~/bin 目录:

  • Tell cygwin to include your ~/bin directory in the search path:

    打开文件 ~/.bash_profile 并取消注释以下段落...

    Open up the file ~/.bash_profile and uncomment the following paragraph ...

    # Set PATH so it includes user's private bin if it exists
    if [ -d "${HOME}/bin" ] ; then
      PATH="${HOME}/bin:${PATH}"
    fi
    

  • 现在,最重要的部分:

  • Now, for the most important part:

    帮助 Win 的原生 PHP 解析 Unix 样式路径的包装脚本(导致问题毕竟是 Windows 不知道如何处理 /cygdrive/... 路径).

    A wrapper script that helps Win's native PHP resolve Unix style paths (which is causing the problem after all as Windows doesn't know how to handle /cygdrive/... paths).

    cd ~/bin
    touch php
    chmod +x php
    

    编辑包装脚本后 ~/bin/php 应为:

    After editing the wrapper script ~/bin/php should read:

    #!/bin/bash
    
    # e.g. php="/cygdrive/c/Program Files (x86)/php/php.exe"
    php="/path/to/php.exe"
    
    for ((n=1; n <= $#; n++)); do
        if [ -e "${!n}" ]; then
            # Converts Unix style paths to Windows equivalents
            path="$(cygpath --mixed ${!n} | xargs)"
    
            case 1 in
                $(( n == 1 )) )
                    set -- "$path" "${@:$(($n+1))}";;
                $(( n < $# )) )
                    set -- "${@:1:$((n-1))}" "$path" ${@:$((n+1)):$#};;
                *)
                    set -- "${@:1:$(($#-1))}" "$path";;
            esac
        fi
    done
    
    "$php" "$@"
    

  • 现在重启你的shell,它应该会正确调用PHP解释器偶然发现了一个 #!/usr/bin/env php shebang.只需发出:

  • Now restart your shell and it should correctly invoke the PHP interpreter whenever it stumbles upon a #!/usr/bin/env php shebang. Simply issue a:

    composer --help
    

  • 这篇关于作曲家赛格温的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆