dsf6778 2017-10-13 08:48
浏览 100
已采纳

无法让Composer在Windows上运行

I'm trying to use https://github.com/phpWhois/phpWhois in my PHP scripts, but can't get it to work. I'm an absolute beginner when it comes to using Composer.

This is what I tried:

  • Cloned the git repo locally
  • Installed Composer for Windows
  • In Powershell, navigated to the local repository
  • Typed composer require. Composer first asked me: Search for a package:, where I simply pressed ENTER. Then, Composer installed various packages in the vendor directory (phpunit, symfony, sebastian, etc.), and it created an autoload.php file.

But if I include that autoload.php in my example script (the basic example on the phpWhois Github main page), it generates the following error:

Fatal error: Class 'phpWhois\Whois' not found in /home/myServer/www/myApp/api/whoistest.php on line 12

Well, the Installation manual on the Github page says I should run

php composer.phar require "phpwhois/phpwhois":"~4.0"

So I tried the following in the Powershell console:

composer require "phpwhois/phpwhois":"~4.0"

[UnexpectedValueException]

Could not parse version constraint :~4.0: Invalid version string ":~4.0"

Then this:

composer require "phpwhois/phpwhois"

Problem 1

  • Conclusion: remove phpwhois/phpwhois dev-master
  • Can only install one of: phpwhois/phpwhois[dev-master, 4.2.3].
  • Can only install one of: phpwhois/phpwhois[dev-master, 4.2.4].
  • Can only install one of: phpwhois/phpwhois[v4.2.5, dev-master].
  • Installation request for phpwhois/phpwhois dev-master -> satisfiable by phpwhois/phpwhois[dev-master].
  • Installation request for phpwhois/phpwhois ^4.2 -> satisfiable by phpwhois/phpwhois[4.2.3, 4.2.4, v4.2.5].

Then this:

composer require "phpwhois/phpwhois:~4.0"

which gave the same error as above.

I tried various other syntaxes to specify the version here, but none of them worked.

Any ideas?

  • 写回答

1条回答 默认 最新

  • douwen1549 2017-10-13 09:06
    关注

    Ok, let's start from the beginning.

    1. Download the latest composer.phar from getcomposer.org (scroll down to manual install).
    2. Put it in your project root directory.
    3. Remove all your current require statements from your composer.json.
    4. Open a terminal and navigate to your project root.
    5. Execute php composer.phar require phpwhois/phpwhois.
    6. Execute php composer.phar install.
    7. Include the autoloader in your code: require vendor/autoload.php.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!