LoginSignup
0
0

【Xserver】久々にcomposerを使ったらエラーが出る

Last updated at Posted at 2024-05-03

XserverでLaravelを用いたアプリをデプロイしているときに、composerでエラーになってvendorフォルダが全くできずハマったので、将来の自分と同じ道でさまよっている方々のためにここに書き残しておきます。

1. 何をしていたか

数年ぶりにXserverにLaravelを用いた新しいアプリを置いていました。その時、うまく起動しないのはvendorフォルダがない、つまりcomposerを用いて必要なプログラムをダウンロードしていないというだけでした。そこで

composer install

を実行するとこんな感じでエラーが出てうまくいきませんでした。

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for laravel/framework v10.26.2 -> satisfiable by laravel/framework[v10.26.2].
    - laravel/framework v10.26.2 requires composer-runtime-api ^2.2 -> no matching package found.
  Problem 2
    - laravel/framework v10.26.2 requires composer-runtime-api ^2.2 -> no matching package found.
    - spatie/laravel-ignition 2.3.0 requires illuminate/support ^10.0 -> satisfiable by laravel/framework[v10.26.2].
    - Installation request for spatie/laravel-ignition 2.3.0 -> satisfiable by spatie/laravel-ignition[2.3.0].

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

2. 原因

composer installでエラーが出ていたのはバージョンが古かったからでした。バージョンは以下のコマンドで調べられます。

composer --version

ちなみにこのようにDeporcatedが出てきましたが、やはり古いんでしょうね。
この時(2024年5月)はとっくにバージョン2が出ていました。

PHP Deprecated:  Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Symfony/Component/Console/Helper/HelperSet.php on line 119

Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Symfony/Component/Console/Helper/HelperSet.php on line 119
Composer version 1.9.2 2020-01-14 16:30:31

3.解決方法

解決するには、composerの最新版を持ってきましょう。まずは以下のcomposer公式サイトに行きます。(検索して行った方がいいかも。)

その中に以下のような感じのコマンドが書かれている部分があると思います。これを順に実行すれば大丈夫です。
*ハッシュチェックと思われる処理があります。以下のコマンドを実行するより、公式サイトに書いてあるコマンドの方を実行した方がいいです。 ハッシュチェックで引っかかったら2番目のコマンドの結果が「Installer corrupt」と出てインストールができません。composer-setup.phpが削除されます。

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

それが終わったら、できたcomposer.pharにパスを通せば大丈夫です。

ホームディレクトリにbinのディレクトリを作成して、composer.pharを移動、composerに名前変えると便利ですよ。

mkdir ~/bin
mv ./composer.phar ~/bin/composer

ディレクトリbinにパスを通せばOKです!

~/.bach_profile
PATH=$HOME/bin:$PATH

4.余談

PHPのバージョンの方が古くてエラーにもなっていませんか?そこはphpのパスを新しいバージョンに移すと解決しますよ。

ホームディレクトリに作成したディレクトリbinにphpのシンボリックリンクを作成しています。

mkdir ~/bin
cd ~/bin
ln -s /opt/php-8.1.22/bin/php php

参考リンク

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