5
3

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 require linecorp/line-bot-sdk」がインストールできなくて躓いたお話

Posted at

LaravelでLINEのMessaging APIを使った開発中に起きたエラーで解決まで時間がかかったので自分と同じことで躓く人の助けになればと記事にしました。

環境

・macOS Catalina v10.15.7
・Docker v20.10.5
・PHP v7.4
・Laravel v6.0.*
・MySQL v5.7

エラー内容

エラー内容は要約すると、「linecorp/line-bot-sdk 7.0.0で要求されたPHP拡張機能socketsがねーぞ」ということでした。

ターミナル
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for linecorp/line-bot-sdk ^7.0 -> satisfiable by linecorp/line-bot-sdk[7.0.0].
    - linecorp/line-bot-sdk 7.0.0 requires ext-sockets * -> the requested PHP extension sockets is missing from your system.

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/etc/php/php.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.

ぐぐった結果

こちらの記事を見つけました!

image.png

ということで意気揚々とphp.iniに追記しました。

php.ini
zend.exception_ignore_args = off
expose_php = on
max_execution_time = 30
max_input_vars = 1000
upload_max_filesize = 64M
post_max_size = 128M
memory_limit = 256M
error_reporting = E_ALL
display_errors = on
display_startup_errors = on
log_errors = on
error_log = /dev/stderr
default_charset = UTF-8
extension=sockets

[Date]
date.timezone = Asia/Tokyo

[mysqlnd]
mysqlnd.collect_memory_statistics = on

[Assertion]
zend.assertions = 1

[mbstring]
mbstring.language = Japanese

しかし・・

何も変わらんどころかなんかWarning出とんぞ

ターミナル
Warning: PHP Startup: Unable to load dynamic library 'sockets' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/sockets (/usr/local/lib/php/extensions/no-debug-non-zts-20190902/sockets: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/sockets.so (/usr/local/lib/php/extensions/no-debug-non-zts-20190902/sockets.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

  Problem 1
    - Installation request for linecorp/line-bot-sdk ^7.0 -> satisfiable by linecorp/line-bot-sdk[7.0.0].
    - linecorp/line-bot-sdk 7.0.0 requires ext-sockets * -> the requested PHP extension sockets is missing from your system.

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/etc/php/php.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.

もう一度エラーメッセージをじっくり見ると

socketsがないだけなら、Dockerfileでインストールすればいいんじゃね」とひらめきました。

image.png

ということで、Dockerfileを書き直しました。

Dockerfile
FROM php:7.4-fpm-buster

# コンテナ内の環境変数
ENV COMPOSER_ALLOW_SUPERUSER=1 \
  COMPOSER_HOME=/composer

# composer
COPY --from=composer:1.10 /usr/bin/composer /usr/bin/composer

# node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs

# package
RUN apt-get update && \
  apt-get -y install git unzip libzip-dev libicu-dev libonig-dev && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/* && \
  docker-php-ext-install intl pdo_mysql zip bcmath sockets

# phpの設定ファイル
COPY ./php.ini /usr/local/etc/php/php.ini

# ディレクトリ
WORKDIR /laravel

以下の行でsocketsを追加しました!

docker-php-ext-install intl pdo_mysql zip bcmath sockets

実行

ターミナル
Using version ^7.0 for linecorp/line-bot-sdk
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing linecorp/line-bot-sdk (7.0.0): Downloading (100%)         
linecorp/line-bot-sdk suggests installing apigen/apigen (Install with roave/better-reflection:dev-master to generate docs)
linecorp/line-bot-sdk suggests installing roave/better-reflection (Required by apigen/apigen:dev-master)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: linecorp/line-bot-sdk
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
67 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

インストール成功です!!

感想

こちらの記事とエラーメッセージが違うのにも関わらず鵜呑みしたのが原因でした。
やっぱりしっかりエラーメッセージ読みましょう!

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?