PHP:Compose環境を作る

公開:2021.12.15 14:21
Docker:PHP環境を作る 3」で作成したDocker上のPHP環境
ここに Composer を入れてみる。
※ とりあえずは Smarty を入れたいため


Composer環境を作る

1. phpコンテナに接続
docker container exec -it (CONTAINERID) bash

2. Composerインストール
https://getcomposer.org/」→ [Download] に記載されてある4行をコンテナに張り付けて実行

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

実行結果:
        root@05fa4e42bbcd:~# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
        Xdebug: [Log Files] File '/tmp/xdebug.log' could not be opened.
        Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 172.25.0.1:9003 (through xdebug.client_host/xdebug.client_port).      
      
2.
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"

実行結果:
  root@05fa4e42bbcd:~# php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
  Xdebug: [Log Files] File '/tmp/xdebug.log' could not be opened.
  Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 172.25.0.1:9003 (through xdebug.client_host/xdebug.client_port).
  Installer verified      
      
3.
php composer-setup.php

実行結果:
  root@05fa4e42bbcd:~# php composer-setup.php
  Xdebug: [Log Files] File '/tmp/xdebug.log' could not be opened.
  Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 172.25.0.1:9003 (through xdebug.client_host/xdebug.client_port).
  All settings correct for using Composer
  Downloading...

  Composer (version 2.9.7) successfully installed to: /root/composer.phar
  Use it: php composer.phar
      
4.
php -r "unlink('composer-setup.php');"

実行結果:
  root@05fa4e42bbcd:~# php -r "unlink('composer-setup.php');"
  Xdebug: [Log Files] File '/tmp/xdebug.log' could not be opened.
  Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 172.25.0.1:9003 (through xdebug.client_host/xdebug.client_port).
      
5. composerを任意のディレクトリから呼び出せるように composer.phar を移動させておく
mv composer.phar /usr/local/bin/composer

3. 動作確認
"composer --version" でComposerのバージョンを表示させてみる。
root@8f2ee824c8e9:/var/www/html# composer --version
Composer version 2.1.14 2021-11-30 10:51:43


Docker PHP Composer

0 件のコメント:

その他の記事