この記事のゴール
- phpenv でPHP拡張をインストールして使えるようにする
前提条件
- phpenv インストール済
- Ubuntuで作業しています
phpenv のインストールについては、前回の記事を参考にしてください。
PHP拡張インストール
こちらのサイトを参考にしました。
![](https://macocci7.net/blog/wp-content/uploads/cocoon-resources/blog-card-cache/30d7f56245c70476c5aa356fe9a90e32.png)
phpenv(php-build)でapcuなどのPHP拡張をインストールする方法
環境変数「PHP_BUILD_INSTALL_EXTENTION」に
「拡張名=バージョン番号」を指定してから
phpenv install を使います。
バージョン番号に「@」を使うと最新版が適用されます。
複数の拡張を指定する場合はスペース区切りで並べます。
今回の例では、PHP8.0.30 に Imagick PHP Extension
を追加した形でインストールしていきます。
Imagickは「MagickWand」を使うので、
事前に「libmagickwand-dev」をインストールします。
sudo apt install libmagickwand-dev
PHP8.0.30 と Imagick PHP拡張をインストールします。
※筆者の環境は既にPHP8.0.30がインストールされています。
※今回上書で再インストールします。
PHP_BUILD_INSTALL_EXTENSION="imagick=@" phpenv install 8.0.30
実行結果:
phpenv: /home/macocci7/.phpenv/versions/8.0.30 already exists
continue with installation? (y/N) y
[Info]: Loaded extension plugin
[Info]: Loaded apc Plugin.
[Info]: Loaded composer Plugin.
[Info]: Loaded github Plugin.
[Info]: Loaded uprofiler Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: Loaded zendopcache Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 8.0.30 into /home/macocci7/.phpenv/versions/8.0.30
[Downloading]: https://www.php.net/distributions/php-8.0.30.tar.bz2
[Info]: Applying patches: /home/macocci7/.phpenv/plugins/php-build/bin/../share/php-build/patches/php-8.0-support-openssl-3.patch
[Preparing]: /tmp/php-build/source/8.0.30
[Compiling]: /tmp/php-build/source/8.0.30
[xdebug]: Installing version 3.3.1
[Skipping]: Already downloaded http://xdebug.org/files/xdebug-3.3.1.tgz
[xdebug]: Compiling xdebug in /tmp/php-build/source/xdebug-3.3.1
[xdebug]: Cleaning up.
Makefile:245: warning: overriding recipe for target 'test'
Makefile:132: warning: ignoring old recipe for target 'test'
[Info]: Enabling Opcache...
[Info]: Done
[imagick]: Installing from source
[imagick]: Updating imagick from Git Master
Removing Makefile.fragments
Removing Makefile.objects
Removing autom4te.cache/
Removing build/
Removing config.h.in
Removing config.log
Removing config.nice
Removing configure
Removing configure.ac
Removing include/
Removing run-tests.php
HEAD is now at 28f2704 Fix variable name on error.
[imagick]: Checkout specified revision: origin/master
HEAD is now at 28f2704 Fix variable name on error.
[imagick]: Compiling imagick in /tmp/php-build/source/imagick-master
[imagick]: Installing imagick configuration in /home/macocci7/.phpenv/versions/8.0.30/etc/conf.d/imagick.ini
[imagick]: Cleaning up.
[Info]: The Log File is not empty, but the Build did not fail. Maybe just warnings got logged. You can review the log in /tmp/php-build.8.0.30.20231230174424.log or rebuild with '--verbose' option
[Success]: Built 8.0.30 successfully.
8.0 => 8.0.30
phpenv の shim をリビルドします。
phpenv rehash
phpenv で PHP8.0.30 に切替します。
phpenv shell 8.0.30
PHPのバージョンを確認します。
php -v
実行結果:
PHP 8.0.30 (cli) (built: Dec 30 2023 17:51:05) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies
with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
Imagickがインストールされているか確認します。
(php -m && php -i) | grep imagick
実行結果:
imagick
Additional .ini files parsed => /home/macocci7/.phpenv/versions/8.0.30/etc/conf.d/imagick.ini,
imagick
imagick module => enabled
imagick module version => @PACKAGE_VERSION@
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
imagick.allow_zero_dimension_images => 0 => 0
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.skip_version_check => 0 => 0
しっかりインストールされていますね。
コメント