LoginSignup
28
30

More than 5 years have passed since last update.

composer で Laravelをダウンロードしようとしたら詰まった話 @ CentOS7

Last updated at Posted at 2019-02-05

composer を利用して Laravelをインストールしようとしたら盛大に詰まったので、解決方法を記載しておきます。

私の環境とバージョンは下記の通りです。

[hoge@hoge ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[hoge@hoge ~]# php -v
PHP 7.2.14 (cli) (built: Jan  8 2019 14:05:15) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Composerの導入

ここら辺は公式ドキュメントを参照しつつ、問題なく進んだ。
https://getcomposer.org/download/

composer-setup.phpを引っ張ってくる

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

-rコマンドはスクリプトタグ<?..?>なしにPHPを実行(run)してくれるオプション。
copy関数の定義はcopy([コピー元], [コピー先])
http://php.net/manual/ja/function.copy.php

php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

48e3236262b...というのはcomposer-setup.phpのハッシュ値のようです。これで、ファイルの確からしさを確認しているんですね。
詳しくはこちらに書いてあります。
https://composer.github.io/pubkeys.html

あとは、

php composer-setup.php

実行したのちに

php -r "unlink('composer-setup.php');"

削除したらひと段落です。
cf) unlink() http://php.net/manual/ja/function.unlink.php

composer.pharファイルが生成されるので、どのユーザーもcomposerを利用できるように場所を移動します。

pharはPHP Archive File の略で、複数の処理を1つのファイルにまとめたもの、だそうです。
https://www.weblio.jp/content/Phar

mv composer.phar /usr/local/bin/composer
composer

composerコマンドを叩いて、なんか色々出てきたら成功です。

Laravelをインストールしようとすると...

ここからが長かった。

composer global require "laravel/installer"
を叩いてみる。

すると...

[hoge@hoge ~]# sudo composer global require "laravel/installer"
Changed current directory to /root/.config/composer
Using version ^2.0 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/installer v2.0.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - laravel/installer v2.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - Installation request for laravel/installer ^2.0 -> satisfiable by laravel/installer[v2.0.0, v2.0.1].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
    - /etc/php.d/20-bz2.ini
    - /etc/php.d/20-calendar.ini
    - /etc/php.d/20-ctype.ini
    - /etc/php.d/20-curl.ini
    - /etc/php.d/20-exif.ini
    - /etc/php.d/20-fileinfo.ini
    - /etc/php.d/20-ftp.ini
    - /etc/php.d/20-gettext.ini
    - /etc/php.d/20-iconv.ini
    - /etc/php.d/20-json.ini
    - /etc/php.d/20-mysqlnd.ini
    - /etc/php.d/20-pdo.ini
    - /etc/php.d/20-phar.ini
    - /etc/php.d/20-sockets.ini
    - /etc/php.d/20-sqlite3.ini
    - /etc/php.d/20-tokenizer.ini
    - /etc/php.d/30-mysqli.ini
    - /etc/php.d/30-pdo_mysql.ini
    - /etc/php.d/30-pdo_sqlite.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

どうやら zip が開けないと言われているようだ。
確認してみる。

[hoge@hoge ~]# php --ri zip
Extension 'zip' not present.

...確かにない。
ちなみに、--riはエクステンションの構成を表示してくれるオプションだ。
cf) https://teratail.com/questions/121649

試行錯誤した結果

私の場合、対応しなければならない問題が3つあった。
先に入力したコマンドを書いちゃいます。

[hoge@hoge ~]# sudo yum install --enablerepo=remi,remi-php72 php-pecl-zip

私はこれでうまく認識されるようになりました。

[hoge@hoge ~]# php --ri zip

zip

Zip => enabled
Zip version => 1.15.4
Libzip headers version => 1.5.1
Libzip library version => 1.5.1

以下、必要だったことと詰まったポイント。

1. php-pecl-zipのインストール

実は、zipファイルを使えるようにしようとyum install php-zipを叩いてみたが、エラーが解消されなかったのだ。

情報を探し回った結果、以下のStack Overflowを発見。
https://stackoverflow.com/questions/46058457/cant-install-laravel-installer-via-composer

On centos 7 I have used:

yum install php-pecl-zip
because any other solution didn't work for me.

peclを知らなかったのだが、PHP Extention Community Libraryのことで、PHPの拡張ライブラリを提供してくれているサービスらしい。
https://ja.wikipedia.org/wiki/PECL

なぜphp-zipではダメだったのかの謎が解明していないので少しもやもやする。

2. remiを利用してインストールしなければならない

これが詰まりポイント2つ目。
私の環境下ではyum install php-pecl zipだけでは不十分でした。

というのも、以前にCentOSのPHP環境を構築した際に、PHP7.2をインストールしてくるために、remiを利用していたのです。だからオプションをつける必要があったみたい。

ここらへん、自分の中でも曖昧だったので、せっかくの機会なので、remiについて調べておきました。

https://akamist.com/blog/archives/648
こちらの記事が大変わかりやすいです。

remiとはRemiさんが管理しているリポジトリの1種です。centOSではyumコマンドを利用してインストールを行いますが、yumが参照するパッケージのインストール元のことです。

記事にあるように、yum repolistコマンドを叩いてみましょう。

[hoge@hoge ~]# yum repolist
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
...
リポジトリー ID           リポジトリー名                                          状態
base/7/x86_64             CentOS-7 - Base                                         10,019
epel/x86_64               Extra Packages for Enterprise Linux 7 - x86_64          12,900
extras/7/x86_64           CentOS-7 - Extras                                          322
...
remi-safe                 Safe Remi's RPM repository for Enterprise Linux 7 - x86  3,142
updates/7/x86_64          CentOS-7 - Updates                                       1,057

remi ... というコマンドを打った覚えのあるひとは、remi-safeがいるはずです。

しかし、yumはデフォルトではremiリポジトリを参照してくれません。何故ならば、remiリポジトリは

yum -y install epel-release
yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

のコマンドを使って後から追加された外部のリポジトリという扱いになるためです。

なので、

--enablerepo=remi,remi-php72

こいつをオプションとして書き加えてあげる必要があるわけです。repoはリポジトリ(Repository)の略だったんですね!

3.unzipコマンドのインストール

私はこれでもう一回怒られました笑

As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
Installing 'unzip' may remediate them.

該当する人はこっそり入れておいてあげてください。これはphpとは無関係なのでremiオプションは不要です。

[hoge@hoge ~]# yum install unzip -y

以上でとりあえずLaravelをインストールするまでの"前段階"が終わりました。。。
(VPSでやろうとするんじゃなかった)

また詰まりポイントが出てきたらシェアしようと思います!

ちなみに、yum
Yellowdog Updater Modified
の略らしいですよ。


追記

後の工程でここら辺も必要になりました!

yum install --enablerepo=remi,remi-php72 php-devel php-mbstring php-pdo php-gd php-xml
28
30
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
28
30