LINE BOTでFlexメッセージなどをテストする必要があり、最新版のline-bot-sdkを別ディレクトリにcomposerでインストールしようとしたところエラーとなりました。

以前はさくらのレンタルサーバーでもcomposer でLINE BOT SDKがインストールできましたが、下記のエラーでLine-bot-sdkのインストールに失敗。。

Using version ^4.5 for linecorp/line-bot-sdk
./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
    - Installation request for linecorp/line-bot-sdk ^4.5 -> satisfiable by linecorp/line-bot-sdk[4.5.0].
    - linecorp/line-bot-sdk 4.5.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/php/7.4/etc/php.ini
    - /usr/local/php/7.4/etc/conf.d/apcu.ini
    - /usr/local/php/7.4/etc/conf.d/mcrypt.ini
    - /usr/local/php/7.4/etc/conf.d/opcache.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, deleting ./composer.json.

エラーはext-socketsがphpで有効になっていない為で、ext-socketsはLINE SDKのcomposer.jsonを見ると最近のアップデートでrequireにext-soketsが追加されていました。

  "require": {
    "php": ">=5.5",
    "ext-curl": "*",
    "ext-json": "*",
    "ext-sockets": "*"



cat /usr/local/php/7.4/etc/php.ini | grep socket
; Default timeout for socket based streams (seconds)
default_socket_timeout = 60

$ ll /usr/local/php/7.4/lib/php/extensions/no-debug-non-zts-20190902/
total 2348
-rw-r--r--  1 root  wheel   124476 Aug  7 09:14
-rw-r--r--  1 root  wheel   595997 Aug  7 09:13
-rw-r--r--  1 root  wheel    61009 Aug  7 09:14
-rw-r--r--  1 root  wheel   312644 Aug  7 09:13
-rwxr-xr-x  1 root  wheel  1185945 Aug  7 09:12


--configure-options [--prefix=/usr/local/php/7.4 --mandir=/usr/local/php/7.4/man --with-config-file-path=/usr/local/php/7.4/etc --with-config-file-scan-dir=/usr/local/php/7.4/etc/conf.d --with-apxs2=/usr/local/apache/bin/apxs --with-openssl --with-zlib --with-curl --enable-exif --enable-gd --with-jpeg --with-webp --with-freetype --with-gettext --with-gmp --with-iconv-dir=/usr/local --enable-intl --enable-mbstring --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-snmp --enable-soap --with-xsl --enable-opcache --with-zip --enable-ftp --with-pear OPENSSL_CFLAGS=-I/usr/include OPENSSL_LIBS=-L/usr/lib -lssl -lcrypto]

まずは、同じバージョンのPHPのソースを落として、解凍したphpのソースディレクトリ内のext内にあるsocketsディレクトリ でビルドを行い、sockets.soを自分のphp.iniで指定します。

$ php -v
PHP 7.4.9 (cli) (built: Aug  7 2020 09:12:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies

$ wget

$cd ./php-src-php-7.4.9/ext/sockets/
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902

$./configure --prefix=/home/○○/php_modules/
$ make

cp ./.libs/ /home/〇〇/php-src-php-7.4.9/ext/sockets/modules/
cp ./.libs/sockets.lai /home/〇〇/php-src-php-7.4.9/ext/sockets/modules/


$  alias php='/usr/local/bin/php -c /home/〇〇/www/php.ini'
$ php ~/bin/composer.phar require linecorp/line-bot-sdk
PHP Warning:  PHP Startup: mailparse: Unable to initialize module
Module compiled with module API=20170718
PHP    compiled with module API=20190902
These options need to match
 in Unknown on line 0
Using version ^4.5 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 (4.5.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)
Package oscarotero/psr7-middlewares is abandoned, you should avoid using it. Use middlewares/* instead.
Writing lock file
Generating autoload files