🐘

Mac に入れた PHP 8.0.1 に足りない拡張を追加して再インストール

2021/01/30に公開
1

https://zenn.dev/chatii/articles/4471a4836d2035

上記 前記事にて phpenv でインストールした PHP 8.0.1 を使って、 Symfony5: The Fast Track に従ってセットアップしていたら、拡張が足りないと言われたので対応したログです

symfony book:check-requirements の結果

symfony book:check-requirements
[OK] Git installed
[OK] PHP installed version 7.3.24 (/usr/bin/php)
[OK] PHP extension "ctype" installed - required
[OK] PHP extension "xml" installed - required
[KO] PHP extension "sodium" not found, please install it - required
[OK] PHP extension "curl" installed - optional - needed only for chapter 17 (Panther)
[KO] PHP extension "zip" not found, please install it - optional - needed only for chapter 17 (Panther)
[OK] PHP extension "gd" installed - optional - needed only for chapter 23 (Imagine)
[KO] PHP extension "redis" not found, please install it - optional - needed only for chapter 11
[OK] PHP extension "tokenizer" installed - required
[KO] PHP extension "intl" not found, please install it - required
[OK] PHP extension "mbstring" installed - required
[KO] PHP extension "amqp" not found, please install it - required
[OK] PHP extension "openssl" installed - required
[OK] PHP extension "json" installed - required
[OK] PHP extension "session" installed - required
[KO] PHP extension "pdo_pgsql" not found, please install it - required
[OK] PHP extension "xsl" installed - required
[OK] Composer installed
[OK] Docker installed
[OK] Docker Compose installed
[KO] Cannot find the Yarn package manager, please install it https://yarnpkg.com/


  You should fix the reported issues before starting reading the book.

[KO] と言われているのは以下の拡張

  • sodium
  • zip
  • redis
  • intl
  • amqp
  • pdo_pgsql

これの他 yarn が必要と言われています (npm install -g yarn で対応)

必要なパッケージ

(前記事からの追加分のみ)

brew install postgresql
brew install libsodium

phpenv install

PHP_BUILD_CONFIGURE_OPTS="--with-bz2=$(brew --prefix bzip2) --with-iconv=$(brew --prefix libiconv) --with-tidy=$(brew --prefix tidy-html5) --with-external-pcre=$(brew --prefix pcre2) --with-sodium --with-zip --enable-intl --with-pdo-pgsql=$(brew --prefix postgresql) --with-pear" \
PHP_BUILD_EXTRA_MAKE_ARGUMENTS="-j$(sysctl -n hw.logicalcpu_max)" \
phpenv install --ini development 8.0.1

pecl パッケージ

pecl channel-update pecl.php.net

Redis

enable igbinary serializer support? [no] : yes のために

pecl install igbinary
echo 'extension=igbinary.so' > ~/.anyenv/envs/phpenv/versions/8.0.1/etc/conf.d/pecl-igbinary.ini

enable lzf compression support? [no] : yes のために

brew install zstd
pecl install redis
echo 'extension=redis.so' > ~/.anyenv/envs/phpenv/versions/8.0.1/etc/conf.d/pecl-redis.ini

AMQP

pecl で公開されているものが古く pecl install amqp だとビルドできないので、ソースをクローンしてきて make する

brew install --build-from-source rabbitmq-c
git clone https://github.com/php-amqp/php-amqp.git
cd php-amqp
phpize
./configure --with-librabbitmq-dir=$(brew --prefix rabbitmq-c)
make && make test
make install
echo 'extension=amqp.so' > ~/.anyenv/envs/phpenv/versions/8.0.1/etc/conf.d/pecl-amqp.ini
cd .. && rm -rf php-amqp

改めて symfony book:check-requirements の結果

symfony book:check-requirements
[OK] Git installed
[OK] PHP installed version 7.3.24 (/usr/bin/php)
[OK] PHP extension "session" installed - required
[OK] PHP extension "xml" installed - required
[KO] PHP extension "pdo_pgsql" not found, please install it - required
[KO] PHP extension "redis" not found, please install it - optional - needed only for chapter 11
[OK] PHP extension "ctype" installed - required
[OK] PHP extension "tokenizer" installed - required
[OK] PHP extension "openssl" installed - required
[KO] PHP extension "sodium" not found, please install it - required
[OK] PHP extension "gd" installed - optional - needed only for chapter 23 (Imagine)
[KO] PHP extension "intl" not found, please install it - required
[OK] PHP extension "mbstring" installed - required
[KO] PHP extension "amqp" not found, please install it - required

あれ?なんで [KO] まだ出てるの??

[OK] PHP installed version 7.3.24 (/usr/bin/php)

(デデーン)

ということで Symfony CLI が呼び出しているPHPが Big Sur のものでした
なんたる凡ミス
とはいえ The Fast Track で必要な拡張には間違いないので、上記作業は無駄ではないです…

Symfony CLI で phpenv の PHP を使う

前記事の作業で php -v で 8.0.1 が動くことは確認しています。そこで symfony php -v を実行してみると

WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Nov 23 2020 06:45:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies

やはり macOS 同梱の PHP が呼ばれています

Symfony CLI が認識している PHP を確認する

symfony local:php:list

┌─────────┬───────────┬─────────┬──────────────┬─────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │   PHP FPM    │ PHP CGI │ Server  │ System? │
├─────────┼───────────┼─────────┼──────────────┼─────────┼─────────┼─────────┤
│ 7.3.24  │ /usr      │ bin/php │ sbin/php-fpm │         │ PHP FPM │ *       │
└─────────┴───────────┴─────────┴──────────────┴─────────┴─────────┴─────────┘

The current PHP version is selected from default version in $PATH

To control the version used in a directory, create a .php-version file that contains the version number (e.g. 7.2 or 7.2.15).
If you're using SymfonyCloud, the version can also be specified in the .symfony.cloud.yaml file.

8.0.1 がいない事になっている… .php-version を設置しても認識しないため Symforny CLI が対応していないと踏み Issue を上げたところで今回の記事はおしまいです。

https://github.com/symfony/cli/issues/408

Discussion