0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

composer update でリポジトリが見つからないエラーがでた

Posted at

状況

独自のライブラリを Laravel に入れていて、ローカルで require したものをサーバ上で update でインストールしようとしたときに遭遇した。

composer update shimoning/custom-monolog
Loading composer repositories with package information

                                                                                                                   
  [Composer\Downloader\TransportException]                                                                         
  The 'https://api.github.com/repos/shimoning/custom-monolog' URL could not be accessed: HTTP/1.1 400 Bad Request  
                                                                                                                   

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [--with-all-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]...

なお、 今回は composer のバージョンをあげたら改善した。

試したこと

  • composer clear-cache
  • composer self-update

プロキシの問題

検索してみるとプロキシがどうたらこうたら、という記事が見つかったが、今回は関係ない。

リポジトリの設定ミス

リポジトリの設定が間違っているのではないかというTipsも見つけたが、require できているのであっているはす。

キャッシュ

こういう時は大体キャッシュだと思って、 composer clear-cache を試してみたけど、改善せず。

バージョン

ではバージョンか?とおもいローカルと見比べてみたところ、サーバの方が古かった。
とりあえずこれを揃えてみる。

composer self-update 1.10.22
Updating to version 1.10.22 (stable channel).
   Downloading (100%)         

                                                                                                          
  [ErrorException]                                                                                        
  rename(/home/user-name/.cache/composer/composer-temp.phar,/usr/local/bin/composer): Permission denied  
                                                                                                          

self-update [-r|--rollback] [--clean-backups] [--no-progress] [--update-keys] [--stable] [--preview] [--snapshot] [--set-channel-only] [--] [<version>]

パーミッションがないからファイルが移動できない、というエラーに遭遇。
本環境では /usr/local/bin/composer を置いているので、このようなエラーになった。
今回は以下で突破したが、環境によっては違うと思うので、エラーをよく読むことをお勧めする(そもそもエラーが出ない可能性もある)。
sudo mv /home/user-name/.cache/composer/composer-temp.phar /usr/local/bin/composer

今回はこの後改善した。

蛇足

上記で「改善した」と書いたが、実際にはメモリエラーに遭遇した。

Loading composer repositories with package information
Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Updating dependencies (including require-dev)
PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 8192 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleSetGenerator.php on line 64

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 8192 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleSetGenerator.php on line 64

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.

試したこと

  • メモリリミットの解除
  • スワップメモリを追加

メモリリミットの解除

COMPOSER_MEMORY_LIMIT=-1 をつけることで、メモリの上限を一時的に解除できる。
具体的には以下のように実行する。

COMPOSER_MEMORY_LIMIT=-1 composer update

php.ini の memory_limit を -1 にすることを勧める記事があるが、絶対にやってはいけない。絶対に。

スワップメモリを追加。

しかし残念ながら、それでもメモリ不足が改善しなかった。
そもそもの最大メモリ量が足りてないようだった。
ということで、スワップメモリを増やすことにした。

スワップメモリの増やし方については、以下の記事を参考にさせていただいた。
https://qiita.com/mozukuzuku/items/efe80a32c15e323c5d7a

上記記事ではスワップメモリが皆無の状態になっている。
実際のサーバ環境ではスワップメモリが既にある可能性があるので、スワップファイル名 ( /var/swap.1 と書かれているところ) などに気をつける。

使用可能なメモリが増えたことを確認したのち、先ほどのメモリリミットの解除で実行する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?