Troubleshooting

This is a list of common pitfalls on using Composer, and how to avoid them.

General

  • Before asking anyone, run composer diagnose to checkfor common problems. If it all checks out, proceed to the next steps.

  • When facing any kind of problems using Composer, be sure to work with thelatest version. See self-update for details.

  • Make sure you have no problems with your setup by running the installer'schecks via curl -sS https://getcomposer.org/installer | php — —check.

  • Ensure you're installing vendors straight from your composer.json viarm -rf vendor && composer update -v when troubleshooting, excluding anypossible interferences with existing vendor installations or composer.lockentries.

Package not found

  • Double-check you don't have typos in your composer.json or repositorybranches and tag names.

  • Be sure to set the rightminimum-stability. To get started or besure this is no issue, set minimum-stability to "dev".

  • Packages not coming from Packagist shouldalways be defined in the root package (the package depending on allvendors).

  • Use the same vendor and package name throughout all branches and tags ofyour repository, especially when maintaining a third party fork and usingreplace.

Package not found on travis-ci.org

  • Check the "Package not found" item above.

  • If the package tested is a dependency of one of its dependencies (cyclicdependency), the problem might be that composer is not able to detect the versionof the package properly. If it is a git clone it is generally alright and Composerwill detect the version of the current branch, but travis does shallow clones sothat process can fail when testing pull requests and feature branches in general.The best solution is to define the version you are on via an environment variablecalled COMPOSER_ROOT_VERSION. You set it to dev-master for example to definethe root package's version as dev-master.Use: before_script: COMPOSER_ROOT_VERSION=dev-master composer install to exportthe variable for the call to composer.

Need to override a package version

Let say your project depends on package A which in turn depends on a specificversion of package B (say 0.1) and you need a different version of thatpackage - version 0.11.

You can fix this by aliasing version 0.11 to 0.1:

composer.json:

  1. {
  2. "require": {
  3. "A": "0.2",
  4. "B": "0.11 as 0.1"
  5. }
  6. }

See aliases for more information.

Memory limit errors

If composer shows memory errors on some commands:

PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <…>

The PHP memory_limit should be increased.

Note: Composer internally increases the memory_limit to 512M.If you have memory issues when using composer, please consider creatingan issue ticket so we can look into it.

To get the current memory_limit value, run:

  1. php -r "echo ini_get('memory_limit').PHP_EOL;"

Try increasing the limit in your php.ini file (ex. /etc/php5/cli/php.ini forDebian-like systems):

  1. ; Use -1 for unlimited or define an explicit value like 512M
  2. memory_limit = -1

Or, you can increase the limit with a command-line argument:

  1. php -d memory_limit=-1 composer.phar <...>

"The system cannot find the path specified" (Windows)

  • Open regedit.
  • Search for an AutoRun key inside HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processoror HKEY_CURRENT_USER\Software\Microsoft\Command Processor.
  • Check if it contains any path to non-existent file, if it's the case, just remove them.

    API rate limit and OAuth tokens

Because of GitHub's rate limits on their API it can happen that Composer promptsfor authentication asking your username and password so it can go ahead with its work.

If you would prefer not to provide your GitHub credentials to Composer you canmanually create a token using the following procedure:

  • Create an OAuth token on GitHub.Read more on this.

  • Add it to the configuration running composer config -g github-oauth.github.com

    Now Composer should install/update without asking for authentication.

proc_open(): fork failed errors

If composer shows proc_open() fork failed on some commands:

PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar

This could be happening because the VPS runs out of memory and has no Swap space enabled.

  1. free -m
  2. total used free shared buffers cached
  3. Mem: 2048 357 1690 0 0 237
  4. -/+ buffers/cache: 119 1928
  5. Swap: 0 0 0

To enable the swap you can use for example:

  1. /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
  2. /sbin/mkswap /var/swap.1
  3. /sbin/swapon /var/swap.1

如果您发现文档中有错误,或者能够帮我们完善文档,请提交到我们的 Github 仓库吧

原文: https://docs.phpcomposer.com/articles/troubleshooting.html