LoginSignup
56
30

More than 5 years have passed since last update.

php-alpineコンテナにxdebugをインストールする時にハマったメモ

Last updated at Posted at 2019-04-15

xdebugをインストールする時に何回もコケたので、その時のエラーも含めて残します。

TL;DR

# apk add autoconf build-base
# pecl install xdebug
# docker-php-ext-enable xdebug

実際のdockerファイルはこちら https://github.com/ucan-lab/docker-laravel5/blob/master/docker/php/Dockerfile

環境

php バージョン

# php -v
PHP 7.3.4 (cli) (built: Apr 10 2019 00:12:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies

xdebug をインストールの実行

xdebug をインストールを試みると Cannot find autoconf エラーが発生しました。

# pecl install xdebug
downloading xdebug-2.7.1.tgz ...
Starting to download xdebug-2.7.1.tgz (230,653 bytes)
.................................................done: 230,653 bytes
69 source files, building
running: phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize' failed

autoconf パッケージが見つからないエラーです。

解決策

autoconf をインストールする。

# apk add autoconf
(1/4) Installing m4 (1.4.18-r1)
(2/4) Installing libbz2 (1.0.6-r6)
(3/4) Installing perl (5.26.3-r0)
(4/4) Installing autoconf (2.69-r2)
Executing busybox-1.29.3-r10.trigger
OK: 108 MiB in 48 packages

autoconf をインストールできたので再実行を試みます...。

xdebug インストールの再実行

xdebug をインストールを再度試みると no acceptable C compiler found エラーが発生しました。

# pecl install xdebug
downloading xdebug-2.7.1.tgz ...
Starting to download xdebug-2.7.1.tgz (230,653 bytes)
.................................................done: 230,653 bytes
69 source files, building
running: phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
building in /tmp/pear/temp/pear-build-defaultuserbIEBoC/xdebug-2.7.1
running: /tmp/pear/temp/xdebug/configure --with-php-config=/usr/local/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... no
checking for gcc... no
configure: error: in `/tmp/pear/temp/pear-build-defaultuserbIEBoC/xdebug-2.7.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
ERROR: `/tmp/pear/temp/xdebug/configure --with-php-config=/usr/local/bin/php-config' failed

ビルドするために必要な gcc g++ make パッケージが足りないエラーです。

解決策1

build-base ビルドのためのグループパッケージが用意されているので、これをインストールします。

# apk add build-base
(1/16) Installing binutils (2.31.1-r2)
(2/16) Installing libmagic (5.35-r0)
(3/16) Installing file (5.35-r0)
(4/16) Installing gmp (6.1.2-r1)
(5/16) Installing isl (0.18-r0)
(6/16) Installing libgomp (8.3.0-r0)
(7/16) Installing libatomic (8.3.0-r0)
(8/16) Installing mpfr3 (3.1.5-r1)
(9/16) Installing mpc1 (1.0.3-r1)
(10/16) Installing gcc (8.3.0-r0)
(11/16) Installing musl-dev (1.1.20-r4)
(12/16) Installing libc-dev (0.7.1-r0)
(13/16) Installing g++ (8.3.0-r0)
(14/16) Installing make (4.2.1-r2)
(15/16) Installing fortify-headers (1.0-r0)
(16/16) Installing build-base (0.5-r1)
Executing busybox-1.29.3-r10.trigger
OK: 264 MiB in 64 packages

解決策2

個別にインストールしてもok。インストールするパッケージが少ない分、個別にした方が速い。

# apk add gcc g++ make
(1/4) Installing m4 (1.4.18-r1)
(2/4) Installing libbz2 (1.0.6-r6)
(3/4) Installing perl (5.26.3-r0)
(4/4) Installing autoconf (2.69-r2)
Executing busybox-1.29.3-r10.trigger
OK: 108 MiB in 48 packages

xdebug インストールの再々実行

# pecl install xdebug
downloading xdebug-2.7.1.tgz ...
Starting to download xdebug-2.7.1.tgz (230,653 bytes)
.................................................done: 230,653 bytes
69 source files, building
running: phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
building in /tmp/pear/temp/pear-build-defaultusergcLNNb/xdebug-2.7.1
running: /tmp/pear/temp/xdebug/configure --with-php-config=/usr/local/bin/php-config

... 省略 ...

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.7.1
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so" to php.ini

xdebug のインストールが成功しました😊

xdebug の有効化

# docker-php-ext-enable xdebug
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/1) Installing .docker-php-ext-enable-deps (0)
OK: 259 MiB in 61 packages
(1/1) Purging .docker-php-ext-enable-deps (0)
OK: 259 MiB in 60 packages

php のバージョン確認

# php -v
PHP 7.3.4 (cli) (built: Apr 10 2019 00:12:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.1, Copyright (c) 2002-2019, by Derick Rethans

with Xdebug ~ がついてるのでインストール&有効化できました!

参考

56
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
56
30